DEFPARAM CumulateOrders = False
DEFPARAM PreLoadBars = 2000
DEFPARAM FLATBEFORE = 000000
divh, divb, ignored = CALL "Divergence RSI with lookback"[11, 76, 1, 1](close)//14-70/30/30
one = 1
if intradaybarindex=0 then
two = 0
endif
if onmarket and three<>tradeindex then
two=two+1
three=tradeindex
endif
TIMEFRAME (default)
//four = CALL "O"
four = (divh < 1) //1000 //aa ici c est divb <
TIMEFRAME (2 minute, updateonclose)//90 min
IF Not OnMarket THEN
five = 0
ELSE
five = five + 1
ENDIF
//six = CALL "K"
six = (divb < 1)//1 //aa ici c est divh <
TIMEFRAME (default)
ONCE seven = 1
IF IntraDayBarIndex = 0 THEN
seven = 1
ENDIF
eight = five
IF Not OnMarket AND eight <> eight[1] THEN
seven = 1
ENDIF
IF six AND seven ANd two<one and four THEN
BUY 10 CONTRACT AT MARKET
seven = 0
ENDIF
//SET TARGET pPROFIT 400
//SET STOP pLOSS 170
nine = 300
ten = 240
IF NOT ONMARKET THEN
eleven=0
ENDIF
IF LONGONMARKET AND close-tradeprice(1)>=nine*pipsize THEN
eleven = tradeprice(1)+ten*pipsize
ENDIF
IF eleven>0 THEN
SELL AT eleven STOP
ENDIF
twelve = 2//12
fourteen = 1//2
IF NOT ONMARKET THEN
fifteen=0
ENDIF
IF LONGONMARKET AND close-tradeprice(1)>=twelve*pipsize THEN
fifteen = tradeprice(1)+fourteen*pipsize
ENDIF
IF fifteen>0 THEN
SELL AT fifteen STOP
ENDIF
//SET TARGET pPROFIT 4//2
//SET STOP pLOSS 100// 10
//https://www.prorealcode.com/topic/breakeven-with-a-technical-indicator/
// BUY
//if ConditionsPurchase AND Not OnMarket then
//BUY 1 lot AT market
//endif
// BREAKEVEN
//SMA20 = Average [aa](close)//20
//once flag = (close >= SMA20)
//if OnMarket AND flag =1 then
//SELL 1 lot AT TRADEPRICE +1 LIMIT
//endif
//
//// TP = HIGH BOLLINGER
//BBH = BollingerUp [bb](close)//20
//C3 = (high >= BBH)
//
//MyConditionsCloture = C3
//
//if MyConditionsCloture AND OnMarket then
//SELL 1 lot AT market
//endif
//SET TARGET pPROFIT 6
//SET STOP pLOSS 200
//------------------------------------------------------
//trailing stop function
trailingstart = 10//4//20 //trailing will start @trailinstart points profit
trailingstep = 4//10//5 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
endif