Hi everyone, I’m new with coding and I would appreciate your support.
I have defined a rule to buy/sell based on some conditions:
IF NOT LongOnMarket and plage and condition1 THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
I would like to add that Take Profit will be done as soon as 2 EMAs are crossing under
AND
I would like to define the Stop Loss at the most recent Lowest price
Could you help ?
Thanks a lot,
Patrice.
For the SL, the most recent low is that of the current bar, when the strategy places the opening order of an operation:
Set Stop Loss abs(close - low)
TP can be detected at this bearish crossover:
IF average[10,0](close) CROSSES UNDER average[100,0](close) THEN
SELL AT MARKET
ENDIF
Thanks. I have tried the following but it is not behaving at all as expected.
Instead of Average I would like as well to work with exponential average.
Here is the code I used which is not working correctly:
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket and condition THEN
BUY 1 CONTRACTS AT MARKET
IF average[8](close) CROSSES UNDER average[20](close) THEN
SELL AT MARKET
ENDIF
ENDIF
// Conditions pour ouvrir une position en vente à découvert
IF NOT ShortOnMarket and condition THEN
SELL 1 CONTRACTS AT MARKET
IF average[8](close) CROSSES OVER average[20](close) THEN
BUY AT MARKET
ENDIF
ENDIF
Thanks a lot for your help
IF average[8,1](close) CROSSES UNDER average[20,1](close) THEN
this will give you EMA
JSParticipant
Senior
EMA => Average[8,1](Close) or Average[20,1](Close)
For short positions use SellShort instead of Sell
Sell will only close a long (Buy) position
Buy versus Sell
SellShort versus ExitShort
Thanks to all working fine now 🙂
Hi
I have still an issue with my code. The code enter the market according to the condition defined. no problem.
Stop loss is ok but Target profit is not taken based on the condition. Could you help ? Many thanks
indicateur2= ExponentialAverage[20](close)
indicateur5= ExponentialAverage[8](close)
c9short= (indicateur5 < indicateur2)
// Conditions pour ouvrir une position acheteuse
IF NOT LongOnMarket and plage and c1long and c1longbis and c1longtiers and c4long and c8long and c9long and c10long THEN
BUY 1 CONTRACTS AT MARKET
SET STOP LOSS 20
IF c9short THEN
SELL 1 CONTRACTS AT MARKET
ENDIF
ENDIF
Thanks again
Move the last ENDIF to immediately BEFORE IF c9short THEN.