Code Summation and Stop Loss
Forums › ProRealTime English forum › ProOrder support › Code Summation and Stop Loss
- This topic has 5 replies, 3 voices, and was last updated 1 year ago by GraHal.
-
-
05/09/2023 at 10:44 AM #214350
Hello all,
I have 2 questions I’m not able to solve. I thought to have undertood how to use summation but probably something is missing. If I want the condition:
C=Close<ExponentialAverage[20] and Close[1]<ExponentialAverage[20] and Close[2]<ExponentialAverage[20] and Close[3]<ExponentialAverage[20] and Close[4]<ExponentialAverage[20] and Close[5]<ExponentialAverage[20]
I want the price to be under EMA 20 for the last 5 candle, why PRT does not give correct to use: C=Summation [5]((Close<ExponentialAverage[20])=5)
what is wrong?
Second question, about stop loss:
c5= highest[5](high)
//condizione per entrare Long
IF NOT longonmarket and my condition then
BUY 1 CONTRACT AT (c5+0.0001*c5) STOP
longstoploss = (close – lowest[5](low) + 0.002)/pipsize
set stop ploss longstoplossSo when my condition is triggered, I want to buy when price goes over at stop limit at the highest of the last 5 candle, and stop loss at the lowest of the same 5 candles. it works sometimes but more often it opens and close position immediately.
someone can help me, please?
thank’s in advance
Alessio
05/09/2023 at 11:01 AM #214355why PRT does not give correct to use: C=Summation [5]((Close<ExponentialAverage[20])=5)
Are you saying you get a syntax error message?
Try GRAPH C to see when C does occur over 1oK bars or more?
05/09/2023 at 11:13 AM #214356more often it opens and close position immediately.
Have you used GRAPH and Cursor Details on your Conditions to easily see what is happening?
Also, in my experience, PRT can give odd results when 0.0001 of a value is used?
Try using different / higher values to get the code working okay then decrease to what values you really want to use to then see at what value the code stops working correctly?
05/09/2023 at 12:11 PM #214378As to the first question, the code seems correct, try placing parenthesis differently:
1C=(Summation[5](Close<ExponentialAverage[20])=5)As to the second question, (c5+0.0001*c5) can also be written as (c5*1.0001) and
12longstoploss = (close – lowest[5](low) + 0.002)/pipsizeset stop ploss longstoplosscan also be written as
12longstoploss = (close – lowest[5](low) + 0.002)set stop loss longstoplossThe above examples are intended to only show different ways to achieve the same goal and to use or not conversions. Both original code snippets are correct.
The issue is usually due to not abiding by the broker’s rule to set pending orders at some distance (which may vary during the day).
Check if between the current price and your entry price there’s enough distance
1 user thanked author for this post.
05/09/2023 at 2:12 PM #214418hi Grahal,
I’ve graphed it and it gives always a line=0
this is the code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedONCE Segnale = 0// Conditions to enter long positions//PRC_Wick Pressure | indicator//23.05.2022//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge//converted from pinescript// --- settingsatrmult = 0.7 //ATR Multiplier (The Wick area is filtered on the basis of atr and this is multiplier to that ATR. The more the multiplier value, the less the signals and vice versa)//boxlength = 16 //Length of Wick Pressure Boxrsiob = 60 //RSI based on which signnals are filteredrsios = 40 //RSI based on which signnals are filtered// --- end of settingsmeersi = rsi[14](close)//bullish wick pressurersibullishcond = meersi < rsios or meersi[1] < rsios or meersi[2] < rsiosll3 = lowest[3](low)lc3 = min(lowest[3](close),lowest[3](open))C1= low<=lc3 and low[1]<=lc3 and low[2]<=lc3 and open>=lc3 and open[1]>=lc3 and open[2]>=lc3 and lc3-ll3>(atrmult*AverageTrueRange[14](close)) and rsibullishcond and close>openif c1 thenc2 = lc3lc3X=Barindexc5= highest[5](high)elsif c2=9999 thenendif//bearish wick pressurersibearishcond = meersi > rsiob or meersi[1] > rsiob or meersi[2] > rsiobhh3 = highest[3](high)hc3 = max(highest[3](close), highest[3](open))C3=high>=hc3 and high[1]>=hc3 and high[2]>=hc3 and open<=hc3 and open[1]<=hc3 and open[2]<=hc3 and hh3-hc3>(atrmult*AverageTrueRange[14](close)) and rsibearishcond and close<openif c3 thenc4 = lc3lc3Y=Barindexc6= Lowest[5](low)elsif c4=0 thenendifC7=Summation [5]((Close<ExponentialAverage[20])=5)C8=Close>ExponentialAverage[20] and Close[1]>ExponentialAverage[20] and Close[2]>ExponentialAverage[20] and Close[3]>ExponentialAverage[20] and Close[4]>ExponentialAverage[20] and Close[5]>ExponentialAverage[20]graph c7//condizione per entrare LongIF NOT longonmarket and C1 and c7 thenBUY 1 CONTRACT AT (c5+0.0001*c5) STOPlongstoploss = (close - lowest[5](low) + 0.002)/pipsizeset stop ploss longstoplossENDIF// Conditions to exit long positionsIF longonmarket and C3 thensell 1 SHARES AT MARKETENDIF//condizione per entrare ShortIF NOT shortonmarket and not LONGONMARKET and c3 and c8 thensellshort 1 CONTRACT AT (c6-0.0001*c6) STOPENDIFIF shortonmarket and C1 thenEXITSHORT AT MARKETENDIF//set stop ploss 30//set stop pprofit 30now I try to modify just like roberto suggests.
05/09/2023 at 6:15 PM #214434I’ve graphed it and it gives always a line=0
Try below and you will get C7 = True on many occasions (DJI, 1 min TF over 1200K bars).
Your code is good, but Condition C7 does not occur 5 times in 5 bars etc?
12C7=Summation [5]((Close<ExponentialAverage[20])=1)GRAPH C7 -
AuthorPosts
Find exclusive trading pro-tools on