Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Stochastic oscillator
1 Views
0 Downloads
0 Favorites
StoXAM
//+------------------------------------------------------------------+ 
//|                                                       StoXAM.mq4 | 
//|                                  Copyright © 2006, Pavel Izhutov | 
//|                                        e-mail: izhutov@yandex.ru | 
//+------------------------------------------------------------------+ 
extern double TakeProfit = 20; 
extern double Lots = 0.1; 
extern double TrailingStop = 30; 
extern double StopLoss = 20;    
extern double MR = 0.02; 
extern double DF = 3; 
double Optimization(){ 
double lot=Lots; 
int    orders=HistoryTotal();      
int    losses=0;                  
lot=NormalizeDouble(AccountFreeMargin()*MR/150.0,1); 
if(DF>0){for(int i=orders-1;i>=0;i--){ 
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; } 
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue; 
if(OrderProfit()>0) break; 
if(OrderProfit()<0) losses++;} 
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DF,1);} 
if(lot<0.1) lot=0.1;return(lot);} 
double Points; 
int init (){ 
Points = MarketInfo (Symbol(), MODE_POINT);return(0);} 
int deinit(){return(0);} 
int start(){ 
int cnt=0, total; 
if(Bars<10){return(0);}  
if(TakeProfit<20){return(0);} 
if(OrdersTotal()>1){return(0);} 
if(Hour()>23 || Hour ()<1){return(0);} 
if(OrdersTotal()<1){    
if(AccountFreeMargin()<(1000*Lots)){return(0);} 
if(iStochastic(Symbol(),0,5,5,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,5,3,MODE_SMA,0,MODE_SIGNAL,0)){OrderSend(Symbol(),OP_SELL,Optimization(),Bid,3,0,Bid-TakeProfit*Points,"I like Rammsteine and Stochastic",16384,0,Red); 
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());return(0);}    
if(iStochastic(Symbol(),0,5,5,3,MODE_SMA,0,MODE_MAIN,0)<iStochastic(NULL,0,5,5,3,MODE_SMA,0,MODE_SIGNAL,0)){OrderSend(Symbol(),OP_BUY,Optimization(),Ask,3,0,Ask+TakeProfit*Points,"I like Rammsteine and Stochastic",16384,0,Red); 
if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());return(0);}return(0);} total=OrdersTotal();for(cnt=0;cnt<total;cnt++){OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()){ 
if(OrderType()==OP_BUY){ 
if(iStochastic(Symbol(),0,5,5,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,5,3,MODE_SMA,0,MODE_SIGNAL,0)){OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);return(0);} 
if(TrailingStop>0){      
if((OrderOpenPrice()-Ask)>(Points*TrailingStop)){ 
if(OrderStopLoss()==0.0 || OrderStopLoss()>(Ask+Points*TrailingStop)){OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Points*TrailingStop,OrderTakeProfit(),0,Red);return(0);}}}}else{ 
if(iStochastic(Symbol(),0,5,5,3,MODE_SMA,0,MODE_MAIN,0)<iStochastic(NULL,0,5,5,3,MODE_SMA,0,MODE_SIGNAL,0)){OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);return(0);} 
if(TrailingStop>0){  
if(Bid-OrderOpenPrice()>Points*TrailingStop){ 
if(OrderStopLoss()<Bid-Points*TrailingStop){OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Points*TrailingStop,OrderTakeProfit(),0,Red);return(0);}}}}}}return(0);}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---