wolfParticipant
Junior
Please help, I need it so when my code goes long, it stays long until a target profit is achieved. My code at the moment will go long but then will be overridden by a short whenever the terms for going short are met but this is wrong.
Please help, thanks
Picture of scenario: https://gyazo.com/31e89bfce217cd811ad21430e27a9404
defparam preloadbars = 150
defparam CUMULATEORDERS = false
indicator1 = ExponentialAverage[20](close)
indicator2 = ExponentialAverage[100](close)
//buy condition
cBuy = (high CROSSES OVER indicator1)
//sell condition
cSell = (indicator1 CROSSES over indicator2)
//stop loss and take profit
set target $profit 1000
If cbuy then
sellshort 11 perpoint at market
endif
If csell then
exitshort at market
endif
if csell then
buy 11 perpoint at market
endif
if cbuy then
sell at market
endif
You should include the following:
If NOT LONGONMARKET/SHORTONMARKET THEN…
eg.
If NOT LONGONMARKET AND cbuy then
sellshort 11 perpoint at market
endif
And vice virsa for a long entry.
This way they won't cancel each other out.
In addition to dwgfx comment you can also run two different systems: one for short positions and one for long positions.
This “costs” you an additional slot of your maximum number of trading Systems but you can also optimize both types of trades completely separate.