marvslater
Declare a global variable (ie outside of function main) called for example isInTrade and set it initially to 0
var isInTrade = 0;
The variable will have three states ie 0 for flat, 1 for long and -1 for short.
In the conditions to go long you will check that isInTrade is not equal to 1 and you will then set it to 1 as a long trade is entered
if(isInTrade != 1 && close() > MAStudy){
trade.Buy(getSymbol(),100,PaperTradeBroker.MARKET) ;
isInTrade = 1;
}
In the conditions to go short you will instead check that isInTrade is not equal to -1 and then set it to -1 once a short trade is entered.
When you execute a trade to either sell a long position or cover a short (without initiating a trade in the opposite direction) set isInTrade to 0
Hope this helps
Alex
Declare a global variable (ie outside of function main) called for example isInTrade and set it initially to 0
var isInTrade = 0;
The variable will have three states ie 0 for flat, 1 for long and -1 for short.
In the conditions to go long you will check that isInTrade is not equal to 1 and you will then set it to 1 as a long trade is entered
if(isInTrade != 1 && close() > MAStudy){
trade.Buy(getSymbol(),100,PaperTradeBroker.MARKET) ;
isInTrade = 1;
}
In the conditions to go short you will instead check that isInTrade is not equal to -1 and then set it to -1 once a short trade is entered.
When you execute a trade to either sell a long position or cover a short (without initiating a trade in the opposite direction) set isInTrade to 0
Hope this helps
Alex
Comment