I have found a logic bug, because I forgot to take note that one trade had already been skipped (after being skipped) despite conditions.
So I added the variable “TradeSkipped” :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
DEFPARAM CumulateOrders = false
ONCE LosingTrade = 0 //initialize variable to allow trading
ONCE TradeSkipped = 0 //initialize variable to mark a trade as skipped (after a loss)
Cond = close CROSSES OVER Average [ 10 ] //condition to buy
IF POSITIONPERF (1 ) < 0 THEN //if the last one was a losing trade...
IF TradeSkipped = 0 THEN
IF LosingTrade = 0 THEN //... and this is the firsr trade afterwards....
LosingTrade = 1 //... then disable trading
ELSE
Cond = 0 //if one losing trade already occurred do not trade and...
LosingTrade = 0 //... enable next trades
TradeSkipped= 1 //mark this trade as skipped
ENDIF
ENDIF
ENDIF
IF Cond THEN //Buy if condition is met (unless disabled)
BUY AT MARKET
LosingTrade = 0 //set variable to its initial value
TradeSkipped = 0
ENDIF
SET TARGET pPROFIT 50
SET STOP pLOSS 20
It should work fine now. Let me know after testing it. Sorry for the inconvenience.
Roberto
1 user thanked author for this post.