Hey, I wanted to know how to average down the position once i entered a trade through the code. That is, when It falls 1.5% of the price (of entry) and goes into losses how to make the code buy again there.
Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums. Thank you 🙂
I moved the topic from the Spanish forum.
There you go (tested on DAX, Daily TF):
DEFPARAM CumulateOrders = True
//
// code to spot any new entry
//
NewTrade = (LOngOnMarket AND ShortOnMarket[1]) OR (LOngOnMarket[1] AND ShortOnMarket) OR (OnMarket AND Not OnMarket[1])
//
// check how many positions are currently open
//
MyPositions = abs(CountOfPosition)
//
// store the new trading price of any additional position
//
IF NewTrade OR (MyPositions > MyPositions[1]) THEN
EntryPrice = TradePrice
ENDIF
//
// clear variables when not OnMrket
//
IF Not OnMarket THEN
EntryPrice = 0
ENDIF
//
// average down whenever a 1.5% drop occurs
//
IF LongOnMarket THEN
IF close <= EntryPrice * 0.985 THEN //1.5% drop
BUY 1 CONTRACT AT Market
ENDIF
ELSIF ShortOnMarket THEN
IF close >= EntryPrice * 1.015 THEN //1.5% drop
SELLSHORT 1 CONTRACT AT Market
ENDIF
ENDIF
//
// example of a strategy (just to test the above code)
//
IF close crosses over average[20,0](close) and not OnMarket THEN
buy 1 Contract at Market
endif
IF close crosses under average[20,0](close) and not OnMarket THEN
sellshort 1 Contract at Market
endif
//
// target profit
//
SET TARGET pPROFIT 100
//
// monitor the entry price
//
graphonprice EntryPrice coloured("Green")