gm74Participant
Average
Hi Everyone
I am having a problem with a problem. I just want some fresh eyes to perhaps give me a different perspective.
Its simple:
If my previous trade was long. Then the next trade cannot be long.
How would I code this simple bit of logic?
Thanks!
George
Hi George
I take it you don’t want to put your code on here? It be so much easier for a skilled coder to look at what your code is doing and propose a solution to your problem in seconds?
Take a look here … sounds a similar issue?
https://www.prorealcode.com/topic/never-two-or-more-time-trading-in-same-direction/
Cheers
GraHal
gm74Participant
Average
Thank you, yes this does help. I was on the right track but never got it exactly. My solution is as follows. Purely in terms of the condition as mentioned. I use the variable “POS”. This seems to have done the trick.
IF c1 and pos<1 THEN
BUY positionsize CONTRACT AT MARKET
ENDIF
if longonmarket then
pos=2
endif
And for short trades the following:
IF c3 and pos>-1 THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
if shortonmarket then
pos=-2
endif