Hello,
I have a hard time finding how to write what I want, simply put let’s say we have a Simple Moving Average 20 Period and a Simple Moving Average 50 Period.
How could I do so when the SMA20 > SMA50 and close < SMA50 a BUY x SHARES AT SMA50 STOP is placed on the SMA50 and if the buy stop is reached and the shares bought, then wait for SMA20 to go below SMA50 then come back above before placing a new buying stop on SMA50? So if SMA20 > SMA50 and close keep going above and below SMA50, only the first time close was below SMA50 the buy stop was placed
It’s the waiting part once a buy stop has been reached that is causing me an issue 😕 If I enter and exit on the same candle I can’t just call IF LongOnMarket and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe
If I enter and exit on the same candle I can’t just call IF LongOnMarket and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe
The solution comprises two parts (pseudo code) :
Once PutLimit = 0
NewOrderGoodToGo = 0
If PutLimit then // Check whether order was filled.
If StrategyProfit <> StrategyProfit[1] then // Somehthing changed ?
// This either tells you're OnMarket now, or that you're foo already again.
If Not OnMarket then
// Prepare condition for new Order.
NewOrderGoodToGo = 1
endif
endif
PutLimit = 0 // Reset.
endif
[...]
If NewOrderGoodToGo and MySMAConditions then
Buy At MyPrice Limit
PutLimit = 1
endif
NewOrderGoodToGo = 0 // Reset.
This is a quick and dirty of course, but I assume sufficient for you to fully work out.
Checking for having been OnMarket within a candle is always a hassle and depending on whether you applied other stuff, my example must be adjusted.
N.b.: IMO it is an omission that PRT does not provide a simple “HasTraded” as a Boolean telling you that a trade occurred in the last bar.
Hint : keep on checking your Ticks in the Optimization Result window. Each count in there implies a “too positive” result, as in-bar multiple trades can not be tracked correctly by PRT. At least always cause the Ticks to be on as per the Editor window checkbox, and ALWAYS backtest from within the button on that window (or else results are erroneous).
PRT does not provide a simple “HasTraded” as a Boolean
LongTriggered[N]
ShortTriggered[N]
Yes, but that would be the same as an If OnMarket which was not true the previous call, right ?
So it remains a kind of a hassle to know whether two events happened (even three can occur) within the bar. An Enter followed by an Exit would not be unambiguously covered with anything.
1
2
LongTriggered[N]
ShortTriggered[N]
no good Snippet link about this fonction LongTriggered ?
1
2
LongTriggered[N]
ShortTriggered[N]
no good Snippet link about this fonction LongTriggered ?
That is quite easy to use :
LongTriggered is True if we entered long on the current candle (otherwise False)
LongTriggered[1] is True if we entered long on the last candle (otherwise False)
- etc
So one way to use it could be
//If we entered Long on the last candle
//Then put a Stop Loss 1 pip below the last candle
IF LongTriggered[1] THEN
SET STOP Price low[1] - 1*PointSize
ENDIF
Just an example, it would be dangerous to use that if the last candle was finally bearish and the SL was put too late
@aldtrading tks you,
I want somethink maybe more complicated 😊
Are there no SellTriggered and ExitShortTriggered variables so I can know when instructions like SELL x SHARES AT y STOP (to exit partially from a position) have been triggered and act accordingly?
you can use CountOfPosition of the current candle and the previous candle to compare the size of the position maybe 😊
Yep I came up with something like this too, just making sure because I found it funny we have the implementation for when entering the positions but not for when exiting them 😁
don’t forget to use ABS when Short :
abs(COUNTOFPOSITION)