Price Data Components
Orders Execution
0
Views
0
Downloads
0
Favorites
BURN_v1_7
//+------------------------------------------------------------------+
//| BURN .mq4 |
//| Copyright © 2011, Khlistov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, http://cmillion.narod.ru"
#property link "cmillion@narod.ru"
/*//+----------------------------------------------------------------+
Ðàáîòà ñîâåòíèêà:
Ñîâåòíèê ðàáîòàåò íà ïåðèîäå H1
Ñîâåòíèê âûñòàâëÿåò îòëîæåííûå îðäåðà â îáå ñòîðîíû íà ðàññòîÿíèè
DeltaPriceUP è DeltaPriceDN îò öåíû îòêðûòèÿ ñåññèè.
Âðåìÿ îòêðûòèÿ ñåññèè çàäàåòñÿ ïåðåìåííûìè:
TimeSession1
TimeSession2
TimeSession3
Çíà÷åíèå ïî óìîë÷àíèþ: 0, 8 è 16.
Âðåìÿ "æèçíè" îòëîæåííîãî îðäåðà - äî ñëåäóþùåé ñåññèè.
Ïðè ïåðâîì çàïóñêå ñîâåòíèê æäåò íà÷àëà áëèæàéøåé ñåññèè, îòëîæåííûé
îðäåð âûñòàâëÿåòñÿ çà âðåìÿ ñåññèè òîëüêî 1 ðàç.
Îòëîæåííûå îðäåðà âûñòàâëÿþòñÿ ñ çàðàíåå îïðåäåëåííûì SL è TP,
ñîîòâåòñòâóþùèì çíà÷åíèÿì óñòàíîâëåííûìè ïåðåìåííûìè:
StopLoss è TakeProfit.
Ïðè 0 çíà÷åíèè ïåðåìåííûõ ñîîòâåòñòâóþùèé èì ñòîï îòñóòñòâóåò.
//-------------------------------- Çàêðûòèå îðäåðîâ
-Ñîâåòíèê êîíòðîëëèðóåò íóëåâîé óðîâåíü ïðîôèòà (áåçóáûòîê), è îò íåãî âûñòàâëÿåò
ïîðòôåëüíûé SL è TP. TP âûñòàâëÿåòñÿ íå îò óðîâíÿ òåêóùåé öåíû, à îò îáùåãî 0 óðîâíÿ.
-Åñëè TakeProfit=0, òî ñîâåòíèê ðàáîòàåò òîëüêî ñî SL. Ïðè ýòîì çàêðûòèå îðäåðîâ
âîçìîæíî òîëüêî ïî SL.
-SL ïåðåìåùàåòñÿ Trailingîì òîëüêî ïðè îáùåì ïîëîæèòåëüíîì ïðîôèòå, íåçàâèñèìî
îò çíà÷åíèÿ StopLoss (StopLoss èñïîëüçóåòñÿ òîëüêî äëÿ ïåðâîíà÷àëüíîãî âûñòàâëåíèÿ
SL ïðè îòêðûòèè îðäåðà), óðîâåíü SL âûáèðàåòñÿ òàêèì îáðàçîì, ÷òîáû ïðè çàêðûòèè
âñåõ îðäåðîâ îäíîãî íàïðàâëåíèÿ ïî SL, ïðèáûëü ñîñòàâèëà íå ìåíåå TrailingStart.
-Â ñîâåòíèêå åñòü óñòàíîâêà SL íà ïðîòèâîïîëîæíûé îðäåð;
Ïðè çíà÷åíèè SLReverseOrder=true ñîâåòíèê âûñòàâëÿåò SL íà óðîâåíü ïðîòèâîïîëîæíîãî
ñòîï îðäåðà.
*///+----------------------------------------------------------------+
extern string x = " ----- Ñåññèÿ 1 ------ ";
extern int TimeSession1 = 3; //íà÷àëî ïåðâîé ñåññèè
extern double DeltaPriceUP1 = 27; //îòñòóï BuyStop îò öåíû îòêðûòèÿ ñåññèè
extern double DeltaPriceDN1 = 23; //îòñòóï SellStop îò öåíû îòêðûòèÿ ñåññèè
extern double TakeProfit1 = 100; //åñëè= 0, òî íåò
extern int StopLoss1 = 20; //åñëè= 0, òî íåò
extern double Lot1 = 1.0;
//+------------------------------------------------------------------+
extern string xx = " ----- Ñåññèÿ 2 ------ ";
extern int TimeSession2 = 11; //íà÷àëî âòîðîé ñåññèè
extern double DeltaPriceUP2 = 27; //îòñòóï BuyStop îò öåíû îòêðûòèÿ ñåññèè
extern double DeltaPriceDN2 = 23; //îòñòóï SellStop îò öåíû îòêðûòèÿ ñåññèè
extern double TakeProfit2 = 100; //åñëè= 0, òî íåò
extern int StopLoss2 = 60; //åñëè= 0, òî íåò
extern double Lot2 = 1.0;
//+------------------------------------------------------------------+
extern string xxx = " ----- Ñåññèÿ 3 ------ ";
extern int TimeSession3 = 16; //íà÷àëî òðåòüåé ñåññèè
extern double DeltaPriceUP3 = 27; //îòñòóï BuyStop îò öåíû îòêðûòèÿ ñåññèè
extern double DeltaPriceDN3 = 23; //îòñòóï SellStop îò öåíû îòêðûòèÿ ñåññèè
extern double TakeProfit3 = 100; //åñëè= 0, òî íåò
extern int StopLoss3 = 0; //åñëè= 0, òî íåò
extern double Lot3 = 1.0;
//+------------------------------------------------------------------+
extern string ïàðàìåòðû.òîðãîâëè = " -- -- ";
extern bool SLReverseOrder =false; //âûñòàâëÿåò SL íà ïðîòèâîïîëîæíûé îðäåð
//-------------------------------- Trailing
extern int TrailingStop = 10; //åñëè= 0, òî íåò òðàëëà
extern int TrailingStart = 20; //íà÷àëà òðàëëà îò 0 ïðîôèòà
extern int DeltaTrailing = 5; //ìèíèìàëüíîå êîë-âî ïóíêòîâ äëÿ ïåðåìåùåíèÿ
extern double KoeffMartin = 1.5; //êîýôôèöèåíò óâåëè÷åíèÿ ëîòà
extern bool revers = false; //ïåðåâîðîò òîðãîâëè
extern int TimeExpiration = 240; //âðåìÿ çàêðûòèÿ îðäåðîâ â ìèíóòàõ åñëè 0 òî äî êîíöà äíÿ
extern int Slippage = 3;
extern color WevesColor = White;
extern int Magic = 123321;
//+------------------------------------------------------------------+
double DeltaPriceUP; //îòñòóï BuyStop îò öåíû îòêðûòèÿ ñåññèè
double DeltaPriceDN; //îòñòóï SellStop îò öåíû îòêðûòèÿ ñåññèè
double TakeProfit; //åñëè= 0, òî íåò
int StopLoss; //åñëè= 0, òî íåò
double Lot;
//+------------------------------------------------------------------+
double MAXLOT,MinLot,NULLPb,NULLPs;
int OkrLOT,STOPLEVEL;
double Points;
int dDayS,dDayB,brh[24];
datetime TimeBarBay,TimeBarSell;
int HourT;
//+------------------------------------------------------------------+
int init()
{string h;
Points = MarketInfo (Symbol(), MODE_POINT);
MinLot = MarketInfo(Symbol(),MODE_MINLOT);
if (MinLot==0.01) OkrLOT = 2;
if (MinLot >0.01) OkrLOT = 1;
if (MinLot >0.1 ) OkrLOT = 0;
ObjectCreate("ÁÀËÀÍÑ", OBJ_LABEL, 0, 0, 0);
ObjectSet("ÁÀËÀÍÑ", OBJPROP_CORNER, 1);
ObjectSet("ÁÀËÀÍÑ", OBJPROP_XDISTANCE, 10 );
ObjectSet("ÁÀËÀÍÑ", OBJPROP_YDISTANCE, 15);
ObjectCreate("äîõîäS", OBJ_LABEL, 0, 0, 0);
ObjectSet("äîõîäS", OBJPROP_CORNER, 1);
ObjectSet("äîõîäS", OBJPROP_XDISTANCE, 10 );
ObjectSet("äîõîäS", OBJPROP_YDISTANCE, 35);
ObjectCreate("äîõîäB", OBJ_LABEL, 0, 0, 0);
ObjectSet("äîõîäB", OBJPROP_CORNER, 1);
ObjectSet("äîõîäB", OBJPROP_XDISTANCE, 10 );
ObjectSet("äîõîäB", OBJPROP_YDISTANCE, 45);
Comment("Copyright © 2011, http://cmillion.narod.ru");
return(0);
}
//+------------------------------------------------------------------+
int start()
{
double OpenPrice,BuyPrice,SellPrice,SL,TP;
int error;
datetime expiration,
StartBarTime=iTime(NULL,60,0);
HourT=Hour();
if(HourT==TimeSession1){
DeltaPriceUP=DeltaPriceUP1;
DeltaPriceDN=DeltaPriceDN1;
TakeProfit=TakeProfit1;
StopLoss=StopLoss1;
Lot=Lot1;}
if(HourT==TimeSession2){
DeltaPriceUP=DeltaPriceUP2;
DeltaPriceDN=DeltaPriceDN2;
TakeProfit=TakeProfit2;
StopLoss=StopLoss2;
Lot=Lot2;}
if(HourT==TimeSession3){
DeltaPriceUP=DeltaPriceUP3;
DeltaPriceDN=DeltaPriceDN3;
TakeProfit=TakeProfit3;
StopLoss=StopLoss3;
Lot=Lot3;}
STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
ObjectSetText("ÁÀËÀÍÑ"," ÁÀËÀÍÑ = "+DoubleToStr(AccountBalance(),2)+" |ñâîá "+DoubleToStr(AccountFreeMargin(),2),8,"Arial",WevesColor);
if (TimeSession1>TimeSession2||TimeSession2>TimeSession3)
{Comment("Íåò ïîñëåäîâàòåëüíîñòè ñåññèé ","\n","Èñïðàâòå âðåìÿ íà÷àëà ñåññèè"); return;}
if ((HourT==TimeSession1 || HourT==TimeSession2 || HourT==TimeSession3) && (TimeBarBay!=StartBarTime || TimeBarSell!=StartBarTime))
{
OpenPrice = NormalizeDouble(iOpen(NULL,60,0),Digits);
if (revers)
{
BuyPrice = NormalizeDouble(OpenPrice-(DeltaPriceDN*Points),Digits);
SellPrice = NormalizeDouble(OpenPrice+(DeltaPriceUP*Points),Digits);
}
else
{
BuyPrice = NormalizeDouble(OpenPrice+(DeltaPriceUP*Points),Digits);
SellPrice = NormalizeDouble(OpenPrice-(DeltaPriceDN*Points),Digits);
}
if (HourT==TimeSession1)
{
if (TimeExpiration==0) expiration = StrToTime(StringConcatenate(Day(),".",Month(),".",Year()," ",TimeSession2,":00:00"));
else expiration = TimeCurrent()+TimeExpiration*60;
}
if (HourT==TimeSession2)
{
if (TimeExpiration==0) expiration = StrToTime(StringConcatenate(Day(),".",Month(),".",Year()," ",TimeSession3,":00:00"));
else expiration = TimeCurrent()+TimeExpiration*60;
}
if (HourT==TimeSession3)
{
if (TimeExpiration==0) expiration = StrToTime(StringConcatenate(Day()+1,".",Month(),".",Year()," ",TimeSession1,":00:00"));
else expiration = TimeCurrent()+TimeExpiration*60;
}
//----
double OOP,OldBuyPrice,OldSellPrice;
datetime tb,ts,OOT;
int OT;
for (int i=0; i<OrdersTotal(); i++)
{ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{ if (Magic==OrderMagicNumber() && OrderSymbol()==Symbol())
{
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
OOT = OrderOpenTime();
OT = OrderType();
if (OT==OP_BUY || OT==OP_BUYLIMIT || OT==OP_BUYSTOP)
{
if (tb<OOT) OldBuyPrice=OOP;
}
if (OT==OP_SELL || OT==OP_SELLLIMIT || OT==OP_SELLSTOP)
{
if (ts<OOT) OldSellPrice=OOP;
}
} } }
//----
if (TimeBarBay!=StartBarTime && BuyPrice!=OldBuyPrice)
{
Lot = LOT(1);
if (TakeProfit>=STOPLEVEL) TP = NormalizeDouble(BuyPrice + TakeProfit * Point,Digits); else TP = 0;
if (StopLoss>=STOPLEVEL) SL = NormalizeDouble(BuyPrice - StopLoss * Point,Digits); else SL = 0;
if (SLReverseOrder && !revers) SL = SellPrice;
if (revers)
{
if (Lot!=0) error=OrderSend(Symbol(),OP_BUYLIMIT ,Lot,BuyPrice,3,SL,TP,"BUYLIMIT BLD",Magic,expiration,Blue);
if (error==-1) Print("Error BUYLIMIT ",GetLastError()," ",Symbol()," Lot ",Lot," Ask ",Ask," Price ",BuyPrice," SL ",SL," TP ",TP," expiration ",TimeToStr(expiration,TIME_DATE|TIME_MINUTES));
}
else
{
if (Lot!=0) error=OrderSend(Symbol(),OP_BUYSTOP ,Lot,BuyPrice,3,SL,TP,"BUYSTOP BLD",Magic,expiration,Blue);
if (error==-1) Print("Error BUYSTOP ",GetLastError()," ",Symbol()," Lot ",Lot," Ask ",Ask," Price ",BuyPrice," SL ",SL," TP ",TP," expiration ",TimeToStr(expiration,TIME_DATE|TIME_MINUTES));
}
if (error!=-1) TimeBarBay=StartBarTime;
}
if (TimeBarSell!=StartBarTime && SellPrice!=OldSellPrice)
{
Lot = LOT(-1);
if (TakeProfit>=STOPLEVEL) TP = NormalizeDouble(SellPrice - TakeProfit * Point,Digits); else TP = 0;
if (StopLoss>=STOPLEVEL) SL = NormalizeDouble(SellPrice + StopLoss * Point,Digits); else SL = 0;
if (SLReverseOrder && !revers) SL = BuyPrice;
if (revers)
{
if (Lot!=0) error=OrderSend(Symbol(),OP_SELLLIMIT,Lot,SellPrice,3,SL,TP,"SELLLIMIT BLD",Magic,expiration,Red );
if (error==-1) Print("Error SELLLIMIT ",GetLastError()," ",Symbol()," Lot ",Lot," Bid ",Bid," Price ",SellPrice," SL ",SL," TP ",TP," expiration ",TimeToStr(expiration,TIME_DATE|TIME_MINUTES));
}
else
{
if (Lot!=0) error=OrderSend(Symbol(),OP_SELLSTOP,Lot,SellPrice,3,SL,TP,"SELLSTOP BLD",Magic,expiration,Red );
if (error==-1) Print("Error SELLSTOP ",GetLastError()," ",Symbol()," Lot ",Lot," Bid ",Bid," Price ",SellPrice," SL ",SL," TP ",TP," expiration ",TimeToStr(expiration,TIME_DATE|TIME_MINUTES));
}
if (error!=-1) TimeBarSell=StartBarTime;
}
}
if (OrdersTotal()>1)
{
Profit();ChanceSLTP();
}
return(0);
}
//+------------------------------------------------------------------+
//| Óðîâåíü áåçóáûòî÷íîñòè |
//| Copyright © 2010, Khlistov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
int Profit()
{
int b,s;
double MargaSell,MargaBuy,price,price_b,price_s,lot,lot_s,lot_b;
color TextColor;
for (int i=0; i<OrdersTotal(); i++)
{ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{ if (Magic==OrderMagicNumber() && OrderSymbol()==Symbol())
{
price = OrderOpenPrice();
lot = OrderLots();
if (OrderType()==OP_BUY )
{
MargaBuy+=OrderProfit();
price_b = price_b+price*lot; b++; lot_b=lot_b+lot;
}
if (OrderType()==OP_SELL)
{
MargaSell+=OrderProfit();
price_s = price_s+price*lot; s++; lot_s=lot_s+lot;
}
} } }
ObjectDelete("NULLPb");
if (b!=0)
{ NULLPb = NormalizeDouble(price_b/lot_b,Digits);
ObjectCreate("NULLPb",OBJ_ARROW,0,Time[0],NULLPb,0,0,0,0);
ObjectSet ("NULLPb",OBJPROP_ARROWCODE,6);
ObjectSet ("NULLPb",OBJPROP_COLOR, Blue);
}
ObjectDelete("NULLPs");
if (s!=0)
{ NULLPs = NormalizeDouble(price_s/lot_s,Digits);
ObjectCreate("NULLPs",OBJ_ARROW,0,Time[0],NULLPs,0,0,0,0);
ObjectSet ("NULLPs",OBJPROP_ARROWCODE,6);
ObjectSet ("NULLPs",OBJPROP_COLOR, Red);
}
if (MargaSell<0) TextColor=Red; else TextColor=Green;
ObjectSetText("äîõîäS",StringConcatenate("SELL îðäåðîâ =",s," ëîò =",DoubleToStr(lot_s,OkrLOT)," äîõîä = ",DoubleToStr(MargaSell,2)),8,"Arial",TextColor);
if (MargaBuy<0) TextColor=Red; else TextColor=Green;
ObjectSetText("äîõîäB",StringConcatenate("BUY îðäåðîâ =",b," ëîò =",DoubleToStr(lot_b,OkrLOT)," äîõîä = ",DoubleToStr(MargaBuy ,2)),8,"Arial",TextColor);
}
//+------------------------------------------------------------------+
//| Îïðåäåëåíèå ëîòà |
//| Copyright © 2010, Khlistov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
double LOT(int tip)
{
double L,MaxBuyLot,MaxSellLot, MargaSell, MargaBuy, lot;
lot=Lot;
for (int i=0; i<OrdersTotal(); i++)
{ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{ if (Magic==OrderMagicNumber() && OrderSymbol()==Symbol())
{ L=OrderLots();
if (OrderType()==OP_BUY )
{ MargaBuy+=OrderProfit();
if (MaxBuyLot<L) MaxBuyLot=L;
}
if (OrderType()==OP_SELL)
{ MargaSell+=OrderProfit();
if (MaxSellLot<L) MaxSellLot=L;
} } } }
if (tip== 1) if (MaxBuyLot !=0) lot=NormalizeDouble(MaxBuyLot*KoeffMartin,OkrLOT); //óâåëè÷èâàåì êàæäóþ ñëåäóþùóþ ñäåëêó íà êîýôô
if (tip==-1) if (MaxSellLot!=0) lot=NormalizeDouble(MaxSellLot*KoeffMartin,OkrLOT);//óâåëè÷èâàåì êàæäóþ ñëåäóþùóþ ñäåëêó íà êîýôô
//--------------- ïðîâåðêà ëîòîâ
MAXLOT = NormalizeDouble(AccountFreeMargin()/MarketInfo(Symbol(),MODE_MARGINREQUIRED)-MinLot,OkrLOT);
if (MAXLOT<0) MAXLOT=0;
if (MAXLOT>MarketInfo(Symbol(),MODE_MAXLOT)) MAXLOT=MarketInfo(Symbol(),MODE_MAXLOT);
if (lot>MAXLOT) lot = MAXLOT;
if (lot<MinLot) lot = MinLot;
if (MAXLOT<MinLot) lot = 0;
return(lot);
}
//+------------------------------------------------------------------+
//| ïåðåìåùåíèå ñòîïîâ |
//| Copyright © 2011, Khlistov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
void ChanceSLTP()//ïåðåíîñ CË è ÒÏ
{
int tip,Ticket;
double OSL,OOP,OTP;
double TPb,SLb,TPs,SLs;
if (NULLPb>0) TPb = NormalizeDouble(NULLPb + Point * TakeProfit,Digits);
SLb = NormalizeDouble(Bid - Point * TrailingStop,Digits);
if (NULLPs>0) TPs = NormalizeDouble(NULLPs - Point * TakeProfit,Digits);
SLs = NormalizeDouble(Ask + Point * TrailingStop,Digits);
for (int i=0; i<OrdersTotal(); i++)
{ if (OrderSelect(i, SELECT_BY_POS))
{ tip = OrderType();
if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
OSL = NormalizeDouble(OrderStopLoss(),Digits);
OTP = NormalizeDouble(OrderTakeProfit(),Digits);
OOP = OrderOpenPrice();
Ticket = OrderTicket();
if (tip==OP_BUY)
{
if (TPb<=Ask+STOPLEVEL*Point || OTP==0) TPb=OTP;
if (SLb>=Bid-STOPLEVEL*Point) SLb=OSL;
if (SLb<NULLPb+TrailingStart*Point) SLb=OSL;
if (SLb<OSL+DeltaTrailing*Point) SLb=OSL;
if (OTP==TPb && OSL==SLb) continue;
if (!OrderModify(Ticket,OOP,SLb,TPb,0,White))
Print("Îøèáêà OrderModify Buy ",OSL," -> ",SLb," ",OTP," -> ",TPb," ",GetLastError());
}
if (tip==OP_SELL)
{
if (TPs>=Bid-STOPLEVEL*Point || OTP==0) TPs=OTP;
if (SLs<=Ask+STOPLEVEL*Point) SLs=OSL;
if (SLs>NULLPs-TrailingStart*Point) SLs=OSL;
if (SLs>OSL-DeltaTrailing*Point && OSL!=0) SLs=OSL;
if (OTP==TPs && OSL==SLs) continue;
if (!OrderModify(Ticket,OOP,SLs,TPs,0,White))
Print("Îøèáêà OrderModify Sell",OSL," -> ",SLs," ",OTP," -> ",TPs," ",GetLastError());
}
}
}
}
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---