Hello,
I wanna use my indices strategy for forex too.
Can someone tell me what I have to do to make it work for the forex markets?
Thanks a lot!
Depends of the strategies’ codes of course.
But you should adapt trading schedules and points calculation (if you use some points values in your code), these are the common things to change first. If you can post a code example, I’ll teach you how 🙂
Hello,
this is the code I try to change:
defparam cumulateorders = false
defparam flatafter = 220000
defparam flatbefore = 080000
if dayofweek=2 then // Tuesday
daytrading=1
if dayofweek=5 then // Friday
daytrading=1
endif
if time =072500 then
myhigh=high
mylow=low
countB=0
countS=0
elsif time >072500 and time <= 080000 then
myhigh=max(high,myhigh)
mylow=min(low,mylow)
TRIGGERLONG=myhigh*pointsize
TRIGGERSHORT=mylow*pointsize
OPENRANGE=(myhigh-mylow)*pointsize
entrylong=TRIGGERLONG+OPENRANGE
entryshort = TRIGGERSHORT-OPENRANGE
currentdate=date
endif
if longonmarket and positionprice<>lastpriceS then
countS = countS+1
lastpriceS = positionprice
endif
if shortonmarket and positionprice<>lastpriceB then
countB = countB+1
lastpriceB = positionprice
endif
if date=currentdate and time >080000 and time <=185500 then
If not longonmarket and daytrading=1 and countS=0 and close < entrylong then
buy 1 shares at entrylong STOP
set stop ploss openrange*3.0
set target profit openrange*1.0
if not shortonmarket and daytrading=1 and countB=0 and close > entryshort then
sellshort 1 shares at entryshort STOP
set stop ploss openrange*3.0
set target profit openrange*1.0
endif
endif
endif
I do not see anything to be adapted for forex trading, but there are wrong copy/paste or you have modified things in the strategy code, so that now the conditional statements don’t follow any logic.
I modified the code to be correct I think, I did not test it.. Your job 🙂 Here it is:
defparam cumulateorders = false
defparam flatafter = 220000
defparam flatbefore = 080000
if dayofweek=2 then // Tuesday
daytrading=1
endif
if dayofweek=5 then // Friday
daytrading=1
endif
if time =072500 then
myhigh=high
mylow=low
countB=0
countS=0
elsif time >072500 and time <= 080000 then
myhigh=max(high,myhigh)
mylow=min(low,mylow)
TRIGGERLONG=myhigh*pointsize
TRIGGERSHORT=mylow*pointsize
OPENRANGE=(myhigh-mylow)*pointsize
entrylong=TRIGGERLONG+OPENRANGE
entryshort = TRIGGERSHORT-OPENRANGE
currentdate=date
endif
if longonmarket and positionprice<>lastpriceS then
countS = countS+1
lastpriceS = positionprice
endif
if shortonmarket and positionprice<>lastpriceB then
countB = countB+1
lastpriceB = positionprice
endif
if date=currentdate and time >080000 and time <=185500 then
If not longonmarket and daytrading=1 and countS=0 and close < entrylong then
buy 1 shares at entrylong STOP
endif
if not shortonmarket and daytrading=1 and countB=0 and close > entryshort then
sellshort 1 shares at entryshort STOP
endif
endif
set stop ploss openrange*3.0
set target profit openrange*1.0
The code works like before… does that mean it wouldn’t have worked for AutoTrading? So I always have to put stop loss and target profit at the bottom?
So it’s not possible to use the code for forex?
This code can be of course used for forex trading. Like I said, I don’t see anything that could not worked on this type of instrument.
Just saw a mistake on the STOP LOSS instruction, you should replace the line 54 with this one instead:
set stop loss openrange*3.0
The code works now, thanks a lot!
Now I have one more question: Is there a possibility that the strategy buys or sells as soon as the price reaches entrylong/entryshort?
At the moment the strategy buys when the next candle reaches entrylong/entryshort after the close was below or above entrylong/entryshort.
So is there another code for “close” when I want to buy exactly when entryshort or -long is reached the first time?
close > entryshort
This strategy should already buy at exact prices of “entrylong” and “entryshort”, because it uses STOP pending orders at these levels. Or maybe I do not understood well your question?
Yes it buys at exact prices, but not when the price is triggered the first time! It buys when it’s triggered the second time.
For example if say buy 1 share at entrylong Stop and entrylong Stop is at 10.000 points, the strategy buys when the course already was over 10.000 points and comes back to 10.000 points at another candle.