However I am a little confused by your adjustment. As we set JustTraded=0 and then the next if condition asks for “if not 0” (line 3 and 18) that means only to take a trade if JustTraded is greater than 0, it should never take a trade at all
Haha, no … Look at this example :
JustTraded = 1
If not 1 then
// Do some Trade
endif
You are just not “digging” the reality about a variable name and assign it the correct value. And I must admit, the way you explain it I can’t even see where it is wrong, but it really is … wrong.
Thus my code above makes no sense but it shows you that only when not 1, you enter that trade. So again :
JustTraded = 0
If not 1 then
// Do some Trade
endif
// It will enter a trade there, right ?
// So this will do too :
JustTraded = 0
If not JustTraded then // Not JustTraded will be True here.
// Do some Trade
endif
// and :
JustTraded = 1
If not 1 then // It *IS* 1 here !! so the Not will give a false.
// Do some Trade ... nah, no trade will be done.
endif
Just try it. And you need to because else orders will cancel each other indeed.
And Sacha, you do know that your code is called at each candle occurring, right ?
And that your code is executed from top to bottom, sequentially ? –> This is why you need to this. Also :
If OnMarktet (etc.) only receives the proper status at the next bar(‘s calling). Thus
// No Position present at this moment.
SELLSHORT ContractSize SHARES AT market
If ShortOnMarket then // This will really be false when the above was executed during the call of this bar !!
// [...]
Endif
Then your Time(frame) elapses and then the If ShortOnMarket will be true. Not because of any SellShort once “again”, but because of that happening in the *previous* bar(‘s-call).
Lastly, looking at the Topic Title (pyramiding) … No offense meant (!), but I would advise not to attempt this when the basic principles are not 100% clear. Thus, please start out with
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
with the notice that this time the comment matches the code (your’s really doesn’t but that will be an old comment, I’m sure).
See what that brings you and how you will be able to buy and sell (Long and Short) with that. Covered that ? then some next steps. And my promise in advance : these aggregated orders are really not easy to do (I mean, track what’s going on when).
And still and always : have fun !