Can I have an example of how to use MaxPositionProfit?
For example, I would like to exit at the close of a bar if the max position profit is greater than X.
Here is some code with my attempt:
Sub MA_CROSS_Exits (SLen As Integer, LLen As Integer, MPTargetLX as Integer, MPTargetSX as Integer) Dim ShortAve As BarArray Dim LongAve As BarArray Dim MPP As BarArray ShortAve = Average(Close, SLen,0) LongAve = Average(Close, LLen,0) If Close > LongAve Then Buy("BuyEnt",1,0,Market,Day) End If If Close < ShortAve Then Sell("SellEnt",1,0,Market,Day) End If 'Exit - Trailing Early Profit Target
MPP = MaxPositionProfit If MPP > MPTargetLX Then ExitShort("eSX","BuyEnt", 1, 0, CloseExit, Day) MPP = 0 End If If MPP > MPTargetSX Then ExitLong("eLX","SellEnt", 1, 0, CloseExit, Day) MPP = 0 End If End Sub
|