This ProBuilder script is designed to track the outcomes of the last three trades and change a flag based on a specific sequence of wins and losses. The code also includes conditions for entering trades based on a moving average crossover strategy, and visualizes the trade outcomes and the flag status on the chart.
ONCE MyProfit1 = 0
ONCE MyProfit2 = 0
ONCE MyProfit3 = 0
ONCE LWL = 0
IF LWL THEN MyProfit1 = 0 ENDIF
If StrategyProfit > StrategyProfit[1] then
MyProfit1 = MyProfit2
MyProfit2 = MyProfit3
MyProfit3 = 1
ElsIf StrategyProfit < StrategyProfit[1] then
MyProfit1 = MyProfit2
MyProfit2 = MyProfit3
MyProfit3 = -1
Endif
LWL = (MyProfit1 = -1) AND (MyProfit2 = 1) AND (MyProfit3 = -1)
IF close crosses over average[20] and Not LongOnMarket then
buy at market
elsif close crosses under average[20] and Not ShortOnMarket then
sellshort at market
endif
set stop ploss 100
set target pprofit 300
graph LWL coloured(255,0,0,255)
graph MyProfit1
graph MyProfit2
graph MyProfit3
Explanation of the Code:
ONCE keyword, ensuring they are set only once when the script starts.Check out this related content for more information:
https://www.prorealcode.com/topic/change-a-variable-flag-after-a-lwl-streak-possible/#post-175070
Visit Link