Rendere possibile un trade long e uno short nella stessa giornata
Forums › ProRealTime forum Italiano › Supporto ProOrder › Rendere possibile un trade long e uno short nella stessa giornata
- This topic has 2 replies, 2 voices, and was last updated 5 years ago by volpiemanuele.
Tagged: Long e Short intraday
-
-
02/07/2019 at 10:10 PM #90786
Ho creato una strategia basata su dei livelli. Funziona correttamente ma non riesco a fargli fare due entrate nella stessa giornata. Mi spiego meglio. Supponiamo si attivi la condizione long. Questa puo’ andare a TP o prendere SL o raggiungere altro livello (quello per lo short). Io vorrei che se va long e va a TP e una volta flat se si attiva nella stessa giornata la condizione short entra anche su quella e viceversa. Ovviamente non si deve attivare nella stessa giornata una stessa posizione due volte (due long o due short no). Inoltre se la posizione è long e non raggiune ne TP ne SL ma si attiva la condizione short va in stop and reverse (questa dovrebbe già funzionare cosi). Spero di essermi spiegato.
Entrata a rottura livelli123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179//-------------------------------------------------------------------------// Main code : Lunch//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000if IntradayBarIndex = 0 thenlx=0sx=0endifonce upper=0once lower=0//starttime = 080000endtime = 120000finaltime= 220000If Time = endtime thenupper=highest[48](high)lower=lowest[48](low)dif=round(abs((lower-upper)*pipsize*pointvalue))dif3=round(dif/3)Rialzo= upper-dif3Ribasso=lower+dif3endif// positionsize and stopspositionsize = 1sl = 0.2 // % Stoplosspt = 0.3// % Profit Targetts = 0.35 // % MFETrailingONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimeFriday=173000tt1 = time >= endtimett2 = time <= finaltimetradetime = tt1 and tt2DayForbidden = 0 // 0=sundaydf = dayofweek <> dayforbidden// setup number of trades intradayif IntradayBarIndex = 0 thenlongtradecounter = 0Shorttradecounter = 0Tradecounter=0endif// general criteriaGeneralCriteria = tradetime and df// trade criteriatcLong = countoflongshares < 1 and longtradecounter < 1 and tradecounter <1tcShort = countofshortshares < 1 and shorttradecounter < 1 and tradecounter <1if close > rialzo thenlx=1elselx=0endifif close < ribasso thensx=1elsesx=0endif// long entryIf GeneralCriteria thenif lx and tcLong thenbuy positionsize contract at marketlongtradecounter=longtradecounter + 1tradecounter=tradecounter+1endifendif// short entryIf GeneralCriteria thenif sx and tcShort thensellshort positionsize contract at marketshorttradecounter=shorttradecounter + 1tradecounter=tradecounter+1endifendifMFETrailing=1WTrailing=1// MFETrailingif MFETrailing thentrailingstop = (tradeprice/100)*tsif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endifif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=trailingstop*pipsize thenpriceexit = MAXPRICE-trailingstop*pipsizeendifendifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pipsize thenpriceexit = MINPRICE+trailingstop*pipsizeendifendifIf onmarket and WTrailing=0 and priceexit>0 thensell at marketexitshort at marketendifendif// exit larry williamsIf WTrailing and MFETrailing thencount=1i=0j=i+1tot=0while count<4 dotot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendifif onmarket and priceexit>0 thenif high<ref thensell at marketendifIf low>ref thenexitshort at marketendifendifendif// exit at closetimeIf onmarket thenif time >= closetime thensell at marketexitshort at marketendifendif// exit friday at set closetimeif onmarket thenif (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendifendif// build-in exitSET TARGET %PROFIT ptSET STOP %LOSS sl02/08/2019 at 12:58 AM #90806Per evitare che possa entrare più volte nella stessa direzione ho aggiunto le variabili GoLong e GoShort che se avranno valore 1 consentiranno di entrare a mercato, altrimenti no. Ad inizio giornata si resettano al valore di default 1 per riprendere la normale operatività.
La linea 24, oppure la 29 della mia versione, devi variarla così (divisione al posto della moltiplicazione per trasformare il prezzo in pips, mentre si usa la moltiplicazione per trasformare i pips in prezzo, come nel trailing stop):
1dif=round(abs((lower-upper)/pipsize*pointvalue))Ad ogni modo adesso mi sembra funzioni (l’ho provato sul mini EurUsd a 30 minuti), provalo:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186//-------------------------------------------------------------------------// Main code : Lunch//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000ONCE GoLong = 1ONCE GoShort = 1if IntradayBarIndex = 0 thenlx=0sx=0GoLong = 1GoShort = 1endifonce upper=0once lower=0//starttime = 080000endtime = 120000finaltime= 220000If Time = endtime thenupper=highest[48](high)lower=lowest[48](low)dif=round(abs((lower-upper)/pipsize*pointvalue))dif3=round(dif/3)Rialzo= upper-dif3Ribasso=lower+dif3endif// positionsize and stopspositionsize = 1sl = 0.2 // % Stoplosspt = 0.3// % Profit Targetts = 0.35 // % MFETrailingONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimeFriday=173000tt1 = time >= endtimett2 = time <= finaltimetradetime = tt1 and tt2DayForbidden = 0 // 0=sundaydf = dayofweek <> dayforbidden// setup number of trades intradayif IntradayBarIndex = 0 thenlongtradecounter = 0Shorttradecounter = 0Tradecounter=0endif// general criteriaGeneralCriteria = tradetime and df// trade criteriatcLong = countoflongshares < 1 and longtradecounter < 1 and tradecounter <1tcShort = countofshortshares < 1 and shorttradecounter < 1 and tradecounter <1if close > rialzo thenlx=1elselx=0endifif close < ribasso thensx=1elsesx=0endif// long entryIf GeneralCriteria thenif lx and tcLong and GoLong thenbuy positionsize contract at marketGoLong = 0longtradecounter=longtradecounter + 1tradecounter=tradecounter+1endifendif// short entryIf GeneralCriteria thenif sx and tcShort and GoShort thensellshort positionsize contract at marketGoShort = 0shorttradecounter=shorttradecounter + 1tradecounter=tradecounter+1endifendifMFETrailing=1WTrailing=1// MFETrailingif MFETrailing thentrailingstop = (tradeprice/100)*tsif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endifif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=trailingstop*pipsize thenpriceexit = MAXPRICE-trailingstop*pipsizeendifendifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pipsize thenpriceexit = MINPRICE+trailingstop*pipsizeendifendifIf onmarket and WTrailing=0 and priceexit>0 thensell at marketexitshort at marketendifendif// exit larry williamsIf WTrailing and MFETrailing thencount=1i=0j=i+1tot=0while count<4 dotot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendifif onmarket and priceexit>0 thenif high<ref thensell at marketendifIf low>ref thenexitshort at marketendifendifendif// exit at closetimeIf onmarket thenif time >= closetime thensell at marketexitshort at marketendifendif// exit friday at set closetimeif onmarket thenif (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendifendif// build-in exitSET TARGET %PROFIT ptSET STOP %LOSS sl02/08/2019 at 6:36 AM #90809Grazie…ho inserito l’impostazione della variabile golong/goshort all’interno della routine IntradayBarIndex cosi si resetta ogni giorno..altrimenti nei giorni successivi non entrava piu’ (la strategia l’ho testata germany cash 1 euro time frame 5 minuti)
Poi ho fatto altra versione che nello stesso giorno puo’ entrare sia long che short ma solo una volta per ciascuna direzione.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185//-------------------------------------------------------------------------// Main code : Lunch//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000if IntradayBarIndex = 0 thenGoLong = 1GoShort = 1lx=0sx=0endifonce upper=0once lower=0//starttime = 080000endtime = 120000finaltime= 220000If Time = endtime thenupper=highest[48](high)lower=lowest[48](low)dif=round(abs((lower-upper)/pipsize*pointvalue))dif3=round(dif/3)Rialzo= upper-dif3Ribasso=lower+dif3endif// positionsize and stopspositionsize = 1sl = 0.2 // % Stoplosspt = 0.3// % Profit Targetts = 0.35 // % MFETrailingONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimeFriday=173000tt1 = time >= endtimett2 = time <= finaltimetradetime = tt1 and tt2DayForbidden = 0 // 0=sundaydf = dayofweek <> dayforbidden// setup number of trades intradayif IntradayBarIndex = 0 thenlongtradecounter = 0Shorttradecounter = 0Tradecounter=0endif// general criteriaGeneralCriteria = tradetime and df// trade criteriatcLong = countoflongshares < 1 and longtradecounter < 1 and tradecounter <1tcShort = countofshortshares < 1 and shorttradecounter < 1 and tradecounter <1if close > rialzo thenlx=1elselx=0endifif close < ribasso thensx=1elsesx=0endif// long entryIf GeneralCriteria thenif lx and tcLong and GoLong thenbuy positionsize contract at marketGoLong = 0longtradecounter=longtradecounter + 1tradecounter=tradecounter+1endifendif// short entryIf GeneralCriteria thenif sx and tcShort and GoShort thensellshort positionsize contract at marketGoShort = 0shorttradecounter=shorttradecounter + 1tradecounter=tradecounter+1endifendifMFETrailing=1WTrailing=1// MFETrailingif MFETrailing thentrailingstop = (tradeprice/100)*tsif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endifif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=trailingstop*pipsize thenpriceexit = MAXPRICE-trailingstop*pipsizeendifendifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pipsize thenpriceexit = MINPRICE+trailingstop*pipsizeendifendifIf onmarket and WTrailing=0 and priceexit>0 thensell at marketexitshort at marketendifendif// exit larry williamsIf WTrailing and MFETrailing thencount=1i=0j=i+1tot=0while count<4 dotot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendifif onmarket and priceexit>0 thenif high<ref thensell at marketendifIf low>ref thenexitshort at marketendifendifendif// exit at closetimeIf onmarket thenif time >= closetime thensell at marketexitshort at marketendifendif// exit friday at set closetimeif onmarket thenif (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendifendif// build-in exitSET TARGET %PROFIT ptSET STOP %LOSS sl123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178//-------------------------------------------------------------------------// Main code : Lunch//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000if IntradayBarIndex = 0 thenGoLong = 1GoShort = 1lx=0sx=0endifonce upper=0once lower=0//starttime = 080000endtime = 120000finaltime= 220000If Time = endtime thenupper=highest[48](high)lower=lowest[48](low)dif=round(abs((lower-upper)/pipsize*pointvalue))dif3=round(dif/3)Rialzo= upper-dif3Ribasso=lower+dif3endif// positionsize and stopspositionsize = 1sl = 0.2 // % Stoplosspt = 0.3// % Profit Targetts = 0.35 // % MFETrailingONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimeFriday=173000tt1 = time >= endtimett2 = time <= finaltimetradetime = tt1 and tt2DayForbidden = 0 // 0=sundaydf = dayofweek <> dayforbidden// setup number of trades intraday// general criteriaGeneralCriteria = tradetime and df// trade criteriaif close > rialzo thenlx=1elselx=0endifif close < ribasso thensx=1elsesx=0endif// long entryIf GeneralCriteria thenif lx and GoLong thenbuy positionsize contract at marketGoLong = 0endifendif// short entryIf GeneralCriteria thenif sx and GoShort thensellshort positionsize contract at marketGoShort = 0endifendifMFETrailing=1WTrailing=1// MFETrailingif MFETrailing thentrailingstop = (tradeprice/100)*tsif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endifif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=trailingstop*pipsize thenpriceexit = MAXPRICE-trailingstop*pipsizeendifendifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pipsize thenpriceexit = MINPRICE+trailingstop*pipsizeendifendifIf onmarket and WTrailing=0 and priceexit>0 thensell at marketexitshort at marketendifendif// exit larry williamsIf WTrailing and MFETrailing thencount=1i=0j=i+1tot=0while count<4 dotot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendifif onmarket and priceexit>0 thenif high<ref thensell at marketendifIf low>ref thenexitshort at marketendifendifendif// exit at closetimeIf onmarket thenif time >= closetime thensell at marketexitshort at marketendifendif// exit friday at set closetimeif onmarket thenif (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendifendif// build-in exitSET TARGET %PROFIT ptSET STOP %LOSS sl -
AuthorPosts
Find exclusive trading pro-tools on