Orders Execution
0
Views
0
Downloads
0
Favorites
Simulator_v1
extern double LOT=0.1;
extern int MAGIC=777;
extern string COMMENT="Simulator";
string lt;
bool rex=false;
bool lin=false;
bool b=false;
bool s=false;
bool p=false;
bool sel=false;
bool mod=false;
bool clo=false;
double st,pr,ce,lot;
int h=0;
//+**************************************************************+
int start(){
Comment("Áàëàíñ = ",AccountBalance()," ; Ïðèáûëü = ", AccountProfit());
if(ObjectFind("BUY")==(-1))init();
lot();
//+--------------------------------------------------------------------------------------------------------------------------------------+
if(ObjectGet("BUY",OBJPROP_XDISTANCE)!=7){b=true;ObjectSet("BUY",OBJPROP_XDISTANCE,7);ObjectSet("BUY",OBJPROP_YDISTANCE,15);}
if(b==true&&ObjectGet("BUY",OBJPROP_XDISTANCE)==7){OrderSend(Symbol(),OP_BUY,lot,NormalizeDouble(Ask,Digits),0,0,0,COMMENT,MAGIC);b=false;return;}
//+--------------------------------------------------------------------------------------------------------------------------------------+
if(ObjectGet("SELL",OBJPROP_XDISTANCE)!=7){s=true;ObjectSet("SELL",OBJPROP_XDISTANCE,7);ObjectSet("SELL",OBJPROP_YDISTANCE,35);}
if(s==true&&ObjectGet("SELL",OBJPROP_XDISTANCE)==7){OrderSend(Symbol(),OP_SELL,lot,NormalizeDouble(Bid,Digits),0,0,0,COMMENT,MAGIC);s=false;return;}
//+--------------------------------------------------------------------------------------------------------------------------------------+
if(ObjectGet("PEN",OBJPROP_XDISTANCE)!=7){p=true;ObjectSet("PEN",OBJPROP_XDISTANCE,7);ObjectSet("PEN",OBJPROP_YDISTANCE,55);}
if(p==true&&ObjectGet("PEN",OBJPROP_XDISTANCE)==7)
{
if(ObjectFind("price")==(-1))
{
//+--------------------------------------------------------------+
pr=WindowPriceMax();
ObjectCreate("prof",OBJ_HLINE,0,0,pr);
ObjectSet("prof",OBJPROP_COLOR,Gold);
ObjectSet("prof",OBJPROP_STYLE,STYLE_SOLID);
//+--------------------------------------------------------------+
ce=(WindowPriceMax()-WindowPriceMin())/2+WindowPriceMin();
ObjectCreate("price",OBJ_HLINE,0,0,ce);
ObjectSet("price",OBJPROP_COLOR,Teal);
ObjectSet("price",OBJPROP_STYLE,STYLE_SOLID);
//+--------------------------------------------------------------+
st=WindowPriceMin();
ObjectCreate("stop",OBJ_HLINE,0,0,st);
ObjectSet("stop",OBJPROP_COLOR,Red);
ObjectSet("stop",OBJPROP_STYLE,STYLE_SOLID);
//+--------------------------------------------------------------+
p=false;return;
}
else
{
double stop=ObjectGet("stop",OBJPROP_PRICE1);
if(stop==st){p=false;ObjectDelete("prof");ObjectDelete("price");ObjectDelete("stop");return;}
double profit=ObjectGet("prof",OBJPROP_PRICE1);
if(profit==pr)profit=0;
double cena=ObjectGet("price",OBJPROP_PRICE1);
if(cena==ce){p=false;ObjectDelete("prof");ObjectDelete("price");ObjectDelete("stop");return;}
if(cena>Bid&&cena>stop)int typ=4;
if(cena>Bid&&cena<stop)typ=3;
if(cena<Bid&&cena<stop)typ=5;
if(cena<Bid&&cena>stop)typ=2;
OrderSend(Symbol(),typ,lot,NormalizeDouble(cena,Digits),0,stop,profit,COMMENT,MAGIC);
ObjectDelete("prof");
ObjectDelete("price");
ObjectDelete("stop");
p=false;return;
}
}
//+--------------------------------------------------------------+
if(ObjectGet("SEL",OBJPROP_XDISTANCE)!=7){sel=true;ObjectSet("SEL",OBJPROP_XDISTANCE,7);ObjectSet("SEL",OBJPROP_YDISTANCE,85);}
if(sel==true&&ObjectGet("SEL",OBJPROP_XDISTANCE)==7)
{
if(OrderSelect(h,SELECT_BY_POS)==true)
{
if(OrderStopLoss()==0)double sps=WindowPriceMin();else sps=OrderStopLoss();
if(OrderTakeProfit()==0)double spp=WindowPriceMax();else spp=OrderTakeProfit();
ObjectDelete("%ds");ObjectDelete("%dc");ObjectDelete("%dp");
ce=OrderOpenPrice();
//+------------------------------------------------------------------+
ObjectCreate("%ds",OBJ_HLINE,0,0,sps);
ObjectSet("%ds",OBJPROP_COLOR,Red);
ObjectSet("%ds",OBJPROP_STYLE,STYLE_SOLID);
//+------------------------------------------------------------------+
ObjectCreate("%dc",OBJ_HLINE,0,0,ce);
ObjectSet("%dc",OBJPROP_COLOR,Tan);
ObjectSet("%dc",OBJPROP_STYLE,STYLE_SOLID);
//+------------------------------------------------------------------+
ObjectCreate("%dp",OBJ_HLINE,0,0,spp);
ObjectSet("%dp",OBJPROP_COLOR,Gold);
ObjectSet("%dp",OBJPROP_STYLE,STYLE_SOLID);
//+------------------------------------------------------------------+
WindowRedraw();h++;
}
else {ObjectDelete("%ds");ObjectDelete("%dc");ObjectDelete("%dp");h=0;}
sel=false;return;
}
//+--------------------------------------------------------------+
if(ObjectGet("MOD",OBJPROP_XDISTANCE)!=7){mod=true;ObjectSet("MOD",OBJPROP_XDISTANCE,7);ObjectSet("MOD",OBJPROP_YDISTANCE,105);}
if(mod==true&&ObjectGet("MOD",OBJPROP_XDISTANCE)==7)
{
if(ObjectFind("%dc")==0)
{OrderSelect(h-1,SELECT_BY_POS);
if(ObjectGet("%ds",OBJPROP_PRICE1)==WindowPriceMin())double sto=0;else sto=ObjectGet("%ds",OBJPROP_PRICE1);
if(ObjectGet("%dp",OBJPROP_PRICE1)==WindowPriceMax())double pro=0;else pro=ObjectGet("%dp",OBJPROP_PRICE1);
OrderModify(OrderTicket(),ObjectGet("%dc",OBJPROP_PRICE1),sto,pro,0);
}
ObjectDelete("%ds");ObjectDelete("%dc");ObjectDelete("%dp");h=0;
mod=false;return;
}
//+--------------------------------------------------------------+
if(ObjectGet("CLO",OBJPROP_XDISTANCE)!=7){clo=true;ObjectSet("CLO",OBJPROP_XDISTANCE,7);ObjectSet("CLO",OBJPROP_YDISTANCE,125);}
if(clo==true&&ObjectGet("CLO",OBJPROP_XDISTANCE)==7)
{
if(ObjectFind("%dc")==0)
{
OrderSelect(h-1,SELECT_BY_POS);
if(OrderType()==0)OrderClose(OrderTicket(),OrderLots(),Bid,3);
if(OrderType()==1)OrderClose(OrderTicket(),OrderLots(),Ask,3);
if(OrderType()>1)OrderDelete(OrderTicket());
}
ObjectDelete("%ds");ObjectDelete("%dc");ObjectDelete("%dp");h=0;
clo=false;return;
}
//+--------------------------------------------------------------+
return;}
//+**************************************************************+
void init(){
//+--------------------------------------------------------------+
ObjectCreate("BUY",OBJ_LABEL,0,0,0);
ObjectSet("BUY", OBJPROP_CORNER,1);
ObjectSet("BUY",OBJPROP_XDISTANCE,7);
ObjectSet("BUY",OBJPROP_YDISTANCE,15);
ObjectSetText("BUY","BUY",14,"Times New Roman",Blue);
//+--------------------------------------------------------------+
ObjectCreate("SELL",OBJ_LABEL,0,0,0);
ObjectSet("SELL", OBJPROP_CORNER,1);
ObjectSet("SELL",OBJPROP_XDISTANCE,7);
ObjectSet("SELL",OBJPROP_YDISTANCE,35);
ObjectSetText("SELL","SELL",14,"Times New Roman",Red);
//+--------------------------------------------------------------+
ObjectCreate("PEN",OBJ_LABEL,0,0,0);
ObjectSet("PEN", OBJPROP_CORNER,1);
ObjectSet("PEN",OBJPROP_XDISTANCE,7);
ObjectSet("PEN",OBJPROP_YDISTANCE,55);
ObjectSetText("PEN","PENDING",14,"Times New Roman",Teal);
//+--------------------------------------------------------------+
ObjectCreate("SEL",OBJ_LABEL,0,0,0);
ObjectSet("SEL", OBJPROP_CORNER,1);
ObjectSet("SEL",OBJPROP_XDISTANCE,7);
ObjectSet("SEL",OBJPROP_YDISTANCE,85);
ObjectSetText("SEL","SELECT",14,"Times New Roman",Tan);
//+--------------------------------------------------------------+
ObjectCreate("MOD",OBJ_LABEL,0,0,0);
ObjectSet("MOD", OBJPROP_CORNER,1);
ObjectSet("MOD",OBJPROP_XDISTANCE,7);
ObjectSet("MOD",OBJPROP_YDISTANCE,105);
ObjectSetText("MOD","MODIFY",14,"Times New Roman",Tan);
//+--------------------------------------------------------------+
ObjectCreate("CLO",OBJ_LABEL,0,0,0);
ObjectSet("CLO", OBJPROP_CORNER,1);
ObjectSet("CLO",OBJPROP_XDISTANCE,7);
ObjectSet("CLO",OBJPROP_YDISTANCE,125);
ObjectSetText("CLO","CLOSE",14,"Times New Roman",Tan);
//+--------------------------------------------------------------+
lt=DoubleToStr(LOT,2);
ObjectCreate("LOT",OBJ_LABEL,0,0,0);
ObjectSet("LOT", OBJPROP_CORNER,3);
ObjectSet("LOT",OBJPROP_XDISTANCE,50);
ObjectSet("LOT",OBJPROP_YDISTANCE,15);
ObjectSetText("LOT",lt,18,"Times New Roman",Gold);
//+--------------------------------------------------------------+
return;}
//+**************************************************************+
void lot(){
//+--------------------------------------------------------------------------------------------------------------------------------------+
if(ObjectGet("LOT",OBJPROP_XDISTANCE)<50){rex=true;ObjectSet("LOT",OBJPROP_XDISTANCE,50);ObjectSet("LOT",OBJPROP_YDISTANCE,15);}
if(rex==true&&ObjectGet("LOT",OBJPROP_XDISTANCE)==50)
{
lt=DoubleToStr(StrToDouble(lt)+LOT,2);
ObjectSetText("LOT",lt,18,"Times New Roman",Gold);
rex=false;return;}
//+--------------------------------------------------------------------------------------------------------------------------------------+
if(ObjectGet("LOT",OBJPROP_XDISTANCE)>50){lin=true;ObjectSet("LOT",OBJPROP_XDISTANCE,50);ObjectSet("LOT",OBJPROP_YDISTANCE,15);}
if(lin==true&&ObjectGet("LOT",OBJPROP_XDISTANCE)==50)
{
lt=DoubleToStr(StrToDouble(lt)-LOT,2);
if(StrToDouble(lt)<LOT)lt=DoubleToStr(LOT,2);
ObjectSetText("LOT",lt,18,"Times New Roman",Gold);
lin=false;return;}
//+--------------------------------------------------------------------------------------------------------------------------------------+
lot=NormalizeDouble(StrToDouble(lt),2);
//+--------------------------------------------------------------------------------------------------------------------------------------+
return;}
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
---