Limitare il trading escludendo ceri orari.
Forums › ProRealTime forum Italiano › Supporto ProOrder › Limitare il trading escludendo ceri orari.
- This topic has 23 replies, 4 voices, and was last updated 2 years ago by robertogozzi.
-
-
07/20/2022 at 9:46 AM #197551
In un codice vorrei escludere la possibilità di funzionare in certi orari.
Grazie
07/20/2022 at 3:59 PM #197573Usa una variabile, chiamiamola
1234OrarioValido =Time >= 100000 AND Time <= 170000 //operare tra le 10 e le 17IF OrarioValido AND MieCondizioniLong THENBUY 1 Contract at MarketENDIFed utilizzala per entrare a mercato (insieme alle altre tue condizioni):
07/21/2022 at 9:00 AM #197611Ma io voglio escludere solo alcune ore.
Grazie
07/21/2022 at 9:27 AM #197614Allora usa questo codice:
1234OrarioNonValido = (Time >= 100000 AND Time <= 120000) OR (Time >= 150000 AND Time <= 170000) //NON operare tra le 10 e le 12, né tra le 15 e le 17IF NOT OrarioNonValido AND MieCondizioniLong THENBUY 1 Contract at MarketENDIFOvviamente puoi aggiungere altre fasce orarie di tua scelta.
07/25/2022 at 11:08 AM #197897Come definisco “Miecondizionilong”?
07/25/2022 at 9:00 PM #19793307/26/2022 at 9:04 AM #197942Ho inserito le righe nel codice che allego e mi dice di definire la variabile “miestrategielong”. Come indicare i segnali?
// Big Three Trading Strategy
// Original Idea from: http://www.tradingstrategyguides.com/big-three-trading-strategy/
// Market: DAX 30
// Time Frame: 1 Hour
// Time Zone: Any
// Spread: 2.9
// Version : 2.8
// Revised on 2017-11-14
Defparam preloadbars = 3000
Defparam cumulateorders =false //true //falseOrarioNonValido = (Time >= 050000 AND Time <= 050000) OR (Time >= 120000 AND Time <= 120000) OR (Time >= 150000 AND Time <= 150000) OR (Time >= 230000 AND Time <=230000) //NON operare tra le 10 e le 12, né tra le 15 e le 17
IF NOT OrarioNonValido AND MieCondizioniLong THEN
BUY 1 Contract at Market
ENDIF//// Optional Function Switch ( 1 = Enable 0 = Disable ) ////
FixedMinMaxStopLoss = 1 // Optional Function 1
TargetProfit = 1 // Optional Function 2
TimeExit = 1 // Optional Function 3
MFETrailing = 1 // Optional Function 4
MoneyManagement = 0 // Optional Function 5//// Core Indicator Parameter Setting ////
// Moving Average Setting (Original: 20, 40, 80)
Fast = fast// Not Optimize
Medium = medium// Not Optimize
Slow = slow // Not Optimize// Look Back Bar (Original: N/A)
CP = 3 // Variables Optimized//// Optional Function ////
// 1) Fixed Min Max Stop Loss Setting
If FixedMinMaxStopLoss then
//Long
MaxLong = mal // by points, Variables Optimized
MinLong = mil// by points, Variables Optimized
//Short
MaxShort = mas // by points, Variables Optimized
MinShort = mis // by points, Variables Optimized
Endif// 2) Take Profit Setting
If TargetProfit then
//Long
TakeProfitLongRate = tpl// by %, Variables Optimized
//Short
TakeProfitShortRate = tps // by %, Variables Optimized
Endif// 3) Time Exit Setting
If TimeExit then
//Long
ONCE maxCandlesLongWithProfit = 78 // by bar, Variables Optimized
ONCE maxCandlesLongWithoutProfit = 66 // by bar, Variables Optimized
//Short
ONCE maxCandlesShortWithProfit = 60 // by bar, Variables Optimized
ONCE maxCandlesShortWithoutProfit = 54 // by bar, Variables Optimized
Endif// 4) MFE Step Setting
If MFETrailing then
//Long
MFELongStep = mefl // by %, Variables Optimized
//Short
MFEShortStep = mefs // by %, Variables Optimized
Endif// 5) Money Management
If MoneyManagement then
LongRisk = 5// by %, Variables Optimized
ShortRisk = 3 // by %, Variables Optimized
CloseBalanceMaxDrop = 80 // by %, Personal preference
Capital = 3000 // by $
Equity = Capital + StrategyProfit
LongMaxRisk = Round(Equity*LongRisk/100)
ShortMaxRisk = Round(Equity*ShortRisk/100)//Max Contract
MaxLongContract = 500 // by contract, Variables Optimized
MaxShortContract = 100 // by contract, Variables Optimized//Check system account balance
If equity<QuitLevel then
Quit
Endif
RecordHighest = MAX(RecordHighest,Equity)
QuitLevel = RecordHighest*((100-CloseBalanceMaxDrop)/100)
Endif// Core indicator
//Big Three MA
FMA = Average[Fast](close) //green coloured(0,255,0)
MMA = Average[Medium](close) //blue coloured(0,0,255)
SMA = Average[Slow](close) //red coloured(255,0,0)// Entry Rules
//Buy Signal
B1 = low > SMA and low>MMA and low>FMA
B2 = high >= highest[CP](high)
BC = B1 and B2//Buy Candle
BC1 = Close[1] < Close[2]
BC2 = Close > Close[1]
BC3 = Close > Open
BCandle = BC1 and BC2 and BC3//Sell Signal
S1 = high < FMA and high<MMA and high<SMA
S2 = low <= lowest[CP](low)
SC = S1 and S2//Sell Candle
SC1 = Close[1] > Close[2]
SC2 = Close < Close[1]
SC3 = Close < Open
SCandle = SC1 and SC2 and SC3// Exit Rules
LongExit = Close crosses under SMA
ShortExit = Close crosses over SMA//Long Entry
If Not LongonMarket and BC and BCandle then
BuyPrice = CloseIf FixedMinMaxStopLoss then
StopLossLong = MIN(MaxLong,MAX(MinLong,(BuyPrice – SMA)))
Else
StopLossLong = BuyPrice – SMA
EndifIf TargetProfit then
TakeProfitLong = StopLossLong * TakeProfitLongRate
TP = TakeProfitLong
EndifSL = StopLossLong
If MoneyManagement then
PositionSizeLong = min(MaxLongContract,(max(2,abs(round((LongMaxRisk/StopLossLong)/PointValue)*pipsize))))
BUY PositionSizeLong CONTRACT AT MARKET
Else
BUY 1 CONTRACT AT MARKET
EndifEndif
//Long Exit
If LongonMarket and LongExit then
sell at market
Endif//short entry
If Not ShortonMarket and SC and SCandle then
SellPrice = CloseIf FixedMinMaxStopLoss then
StopLossShort = MIN(MaxShort,MAX(MinShort,(SMA – SellPrice)))
Else
StopLossShort = SMA – SellPrice
EndifIf TargetProfit then
TakeProfitShort = StopLossShort * TakeProfitShortRate
TP = TakeProfitShort
EndifSL = StopLossShort
If MoneyManagement then
PositionSizeShort = min(MaxShortContract,(max(2,abs(round((ShortMaxRisk/StopLossShort)/PointValue)*pipsize))))
SELLSHORT PositionSizeShort CONTRACT AT MARKET
Else
SELLSHORT 1 CONTRACT AT MARKET
EndifEndif
//Short Exit
If ShortonMarket and ShortExit then
exitshort at market
Endif// Time Exit
If TimeExit then
If LongonMarket then
posProfit = (((close – positionprice) * pointvalue) * countofposition) / pipsize
elsif ShortonMarket then
posProfit = (((positionprice – close) * pointvalue) * countofposition) / pipsize
Endifm1 = posProfit > 0 AND (BarIndex – TradeIndex) >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND (BarIndex – TradeIndex) >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND (BarIndex – TradeIndex) >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND (BarIndex – TradeIndex) >= maxCandlesShortWithoutProfit// take profit after max candles
IF LONGONMARKET AND (m1 OR m3) THEN
sell at market
endif
IF SHORTONMARKET AND (m2 OR m4) THEN
exitshort at market
endif
Endif//MFE Trailing stop
If MFETrailing thenMFELong = (TakeProfitLong/MFELongStep)
MFEShort = (TakeProfitShort/MFEShortStep)If not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
EndifIf longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
If MAXPRICE-tradeprice(1)>=MFELong*pointsize then
priceexit = MAXPRICE-MFELong*pointsize
Endif
EndifIf shortonmarket then
MINPRICE = MIN(MINPRICE,close)
If tradeprice(1)-MINPRICE>=MFEShort*pointsize then
priceexit = MINPRICE+MFEShort*pointsize
Endif
EndifIf onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
Endif
Endif// Stop Loss a
SET STOP LOSS SL// Target Profit
If TargetProfit then
SET TARGET PROFIT TP
Endif07/26/2022 at 9:51 AM #197945OrarioNonValido va bene come lo hai definito, anche se, quando il primo ed il secondo orario sono uguali puoi mettere solo OrarioNonValido = (Time = 050000) OR (Time = 120000) OR (Time = 150000) OR (Time =230000), comunque la forma che hai usato è corretta.
Quello che non va bene sono le 3 righe successive. NON devi creare delle righe apposite con BUY o SELLSHORT, ma DEVI solo aggiungere IF NOT OrarioNonValido alle tue normali condizioni per entrare in posizione. Non esiste la variabile MieCondizioniLong, come ha scritto MauroPro, è semplicemente un modo per indicare una qualunque delle tue condizioni per aprire un’operazione, non necessariamente LONG, io ho indicato Long semplicemente perché ho fatto un esempio con BUY.
Quindi, dove tu hai scrtto If Not ShortonMarket and SC and SCandle then, devi scrivere IF NOT OrarioNonValido AND Not ShortonMarket and SC and SCandle then. Lo stesso devi fare per le operazioni Long.
07/27/2022 at 3:21 PM #197998Ho fatto esattamente (almeno credo) come da te descritto, ma facendolo girare in un test, non mi fa nessuna operazione.
Grazie
07/27/2022 at 11:07 PM #198004Posta l’ultimo codice che hai usato, con le modifiche.
L’hai uasto sul grafico orario? su quale strumento?
07/28/2022 at 8:57 AM #198022Il sottostante è il dax 1 Euro il tf 1 ora, di seguito il codice
Defparam preloadbars = 3000
Defparam cumulateorders =false //true //falseOrarioNonValido = (Time = 050000 ) OR (Time = 120000 ) OR (Time= 150000) OR (Time =230000) //NON operare tra le 10 e le 12, né tra le 15 e le 17
//// Optional Function Switch ( 1 = Enable 0 = Disable ) ////
FixedMinMaxStopLoss = 1 // Optional Function 1
TargetProfit = 1 // Optional Function 2
TimeExit = 1 // Optional Function 3
MFETrailing = 1 // Optional Function 4
MoneyManagement = 0 // Optional Function 5//// Core Indicator Parameter Setting ////
// Moving Average Setting (Original: 20, 40, 80)
Fast = fast// Not Optimize
Medium = medium// Not Optimize
Slow = slow // Not Optimize// Look Back Bar (Original: N/A)
CP = 3 // Variables Optimized//// Optional Function ////
// 1) Fixed Min Max Stop Loss Setting
If FixedMinMaxStopLoss then
//Long
MaxLong = mal // by points, Variables Optimized
MinLong = mil// by points, Variables Optimized
//Short
MaxShort = mas // by points, Variables Optimized
MinShort = mis // by points, Variables Optimized
Endif// 2) Take Profit Setting
If TargetProfit then
//Long
TakeProfitLongRate = tpl// by %, Variables Optimized
//Short
TakeProfitShortRate = tps // by %, Variables Optimized
Endif// 3) Time Exit Setting
If TimeExit then
//Long
ONCE maxCandlesLongWithProfit = 78 // by bar, Variables Optimized
ONCE maxCandlesLongWithoutProfit = 66 // by bar, Variables Optimized
//Short
ONCE maxCandlesShortWithProfit = 60 // by bar, Variables Optimized
ONCE maxCandlesShortWithoutProfit = 54 // by bar, Variables Optimized
Endif// 4) MFE Step Setting
If MFETrailing then
//Long
MFELongStep = mefl // by %, Variables Optimized
//Short
MFEShortStep = mefs // by %, Variables Optimized
Endif// 5) Money Management
If MoneyManagement then
LongRisk = 5// by %, Variables Optimized
ShortRisk = 3 // by %, Variables Optimized
CloseBalanceMaxDrop = 80 // by %, Personal preference
Capital = 3000 // by $
Equity = Capital + StrategyProfit
LongMaxRisk = Round(Equity*LongRisk/100)
ShortMaxRisk = Round(Equity*ShortRisk/100)//Max Contract
MaxLongContract = 500 // by contract, Variables Optimized
MaxShortContract = 100 // by contract, Variables Optimized//Check system account balance
If equity<QuitLevel then
Quit
Endif
RecordHighest = MAX(RecordHighest,Equity)
QuitLevel = RecordHighest*((100-CloseBalanceMaxDrop)/100)
Endif// Core indicator
//Big Three MA
FMA = Average[Fast](close) //green coloured(0,255,0)
MMA = Average[Medium](close) //blue coloured(0,0,255)
SMA = Average[Slow](close) //red coloured(255,0,0)// Entry Rules
//Buy Signal
B1 = low > SMA and low>MMA and low>FMA
B2 = high >= highest[CP](high)
BC = B1 and B2//Buy Candle
BC1 = Close[1] < Close[2]
BC2 = Close > Close[1]
BC3 = Close > Open
BCandle = BC1 and BC2 and BC3//Sell Signal
S1 = high < FMA and high<MMA and high<SMA
S2 = low <= lowest[CP](low)
SC = S1 and S2//Sell Candle
SC1 = Close[1] > Close[2]
SC2 = Close < Close[1]
SC3 = Close < Open
SCandle = SC1 and SC2 and SC3// Exit Rules
LongExit = Close crosses under SMA
ShortExit = Close crosses over SMA//Long Entry
If Not OrarioNonValido AND LongonMarket and BC and BCandle then
BuyPrice = CloseIf FixedMinMaxStopLoss then
StopLossLong = MIN(MaxLong,MAX(MinLong,(BuyPrice – SMA)))
Else
StopLossLong = BuyPrice – SMA
EndifIf TargetProfit then
TakeProfitLong = StopLossLong * TakeProfitLongRate
TP = TakeProfitLong
EndifSL = StopLossLong
If MoneyManagement then
PositionSizeLong = min(MaxLongContract,(max(2,abs(round((LongMaxRisk/StopLossLong)/PointValue)*pipsize))))
BUY PositionSizeLong CONTRACT AT MARKET
Else
BUY 1 CONTRACT AT MARKET
EndifEndif
//Long Exit
If LongonMarket and LongExit then
sell at market
Endif//short entry
If Not OrarioNonValido AND ShortonMarket and SC and SCandle then
SellPrice = CloseIf FixedMinMaxStopLoss then
StopLossShort = MIN(MaxShort,MAX(MinShort,(SMA – SellPrice)))
Else
StopLossShort = SMA – SellPrice
EndifIf TargetProfit then
TakeProfitShort = StopLossShort * TakeProfitShortRate
TP = TakeProfitShort
EndifSL = StopLossShort
If MoneyManagement then
PositionSizeShort = min(MaxShortContract,(max(2,abs(round((ShortMaxRisk/StopLossShort)/PointValue)*pipsize))))
SELLSHORT PositionSizeShort CONTRACT AT MARKET
Else
SELLSHORT 1 CONTRACT AT MARKET
EndifEndif
//Short Exit
If ShortonMarket and ShortExit then
exitshort at market
Endif// Time Exit
If TimeExit then
If LongonMarket then
posProfit = (((close – positionprice) * pointvalue) * countofposition) / pipsize
elsif ShortonMarket then
posProfit = (((positionprice – close) * pointvalue) * countofposition) / pipsize
Endifm1 = posProfit > 0 AND (BarIndex – TradeIndex) >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND (BarIndex – TradeIndex) >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND (BarIndex – TradeIndex) >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND (BarIndex – TradeIndex) >= maxCandlesShortWithoutProfit// take profit after max candles
IF LONGONMARKET AND (m1 OR m3) THEN
sell at market
endif
IF SHORTONMARKET AND (m2 OR m4) THEN
exitshort at market
endif
Endif//MFE Trailing stop
If MFETrailing thenMFELong = (TakeProfitLong/MFELongStep)
MFEShort = (TakeProfitShort/MFEShortStep)If not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
EndifIf longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
If MAXPRICE-tradeprice(1)>=MFELong*pointsize then
priceexit = MAXPRICE-MFELong*pointsize
Endif
EndifIf shortonmarket then
MINPRICE = MIN(MINPRICE,close)
If tradeprice(1)-MINPRICE>=MFEShort*pointsize then
priceexit = MINPRICE+MFEShort*pointsize
Endif
EndifIf onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
Endif
Endif// Stop Loss a
SET STOP LOSS SL// Target Profit
If TargetProfit then
SET TARGET PROFIT TP
Endif08/01/2022 at 4:56 PM #198297Non funziona?
08/02/2022 at 4:05 PM #198367No, perché mancano delle variabili, probabilmente sono nell’ottimizzatore.
Allega il file ITF.
08/03/2022 at 9:13 AM #198398In allegato il file Itf
08/03/2022 at 5:51 PM #198438Sostituisci la riga 133 con:
1If Not OrarioNonValido AND Not OnMarket and BC and BCandle thene la riga 164 con:
1If Not OrarioNonValido AND Not OnMarket and SC and SCandle thenperché per entrare NON può attendere di essere già a mercato!
-
AuthorPosts
Find exclusive trading pro-tools on