Author: <<<REZA YOOSEFI>>> MONEY TRANSPORTER Corp.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains close prices for each barSeries array that contains the lowest prices of each barSeries array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reachedChecks for the total of closed orders
0 Views
0 Downloads
0 Favorites
Scalper
//+------------------------------------------------------------------+
//|                                                      6Candle.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "   <<<REZA YOOSEFI>>>   MONEY TRANSPORTER Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

    long account_number=5872255;                                                             


    long balance=300000;
    datetime expire=D'2025.05.01 12:30:00'; //year.month.day

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int Magic=110;
ENUM_TIMEFRAMES TimeFrame=5;
int MinSizeCandle=70;
int MaxSizeCandle=200;
double Lot=0.1;
int GapStart=1;
int GapSL=70;
int TP=300;
bool TrailingStop=true;
int Trail=1;
bool Trade,orderbuy,ordersell,wwe;
double high,low;
string T6h,T6l;
bool trade=false;
input int    spread=8;
double vPoint; 
int vSlippage; 
double pips2dbl, pips2point, pipValue, minGapStop, maxSlippage;



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {
   bs();
   check();
   pos();
   if(TrailingStop)
      trail();
  }
//+------------------------------------------------------------------+
void trail()
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      wwe=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==Magic&&OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&Ask-Trail*Point>OrderOpenPrice()&&
         Bid-Trail*Point>OrderStopLoss() && OrderProfit()*2>OrderCommission())
         wwe=OrderModify(OrderTicket(),OrderOpenPrice()*Point,Bid-Trail*Point,OrderTakeProfit(),0,clrYellow);
         Comment("Profit for the order = ",MathRound(OrderProfit()),"\n","Commission for the order = ",MathRound(OrderCommission())); 
      if(OrderMagicNumber()==Magic&&OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&Bid+Trail*Point<OrderOpenPrice()&&
         Ask+Trail*Point<OrderStopLoss() && OrderProfit()*2>OrderCommission())
         wwe=OrderModify(OrderTicket(),OrderOpenPrice()*Point,Ask+Trail*Point,OrderTakeProfit(),0,clrYellow);
         Comment("Profit for the order = ",MathRound(OrderProfit()),"\n","Commission for the order = ",MathRound(OrderCommission())); 

     }
    
  
  }
 
//+------------------------------------------------------------------+
          
void pos()
  {
  if(AccountNumber()==account_number){
   // if(AccountBalance()<=balance){
      if(TimeCurrent()<=expire){
        if(  MarketInfo(NULL,MODE_SPREAD)<=spread){
   if(Trade&&Ask>high+GapStart*Point&&!orderbuy)
     {
      
      wwe=OrderSend(NULL,OP_BUY,AccountBalance()/300,Ask,0, high-GapSL*Point,Ask+TP*Point,"",Magic,0,clrBlue);
      Trade=false;
      ObjectSetInteger(0,T6h,OBJPROP_RAY_RIGHT,false);
      ObjectSetInteger(0,T6l,OBJPROP_RAY_RIGHT,false);
      TrendPointChange(0,T6h,1,iTime(NULL,TimeFrame,0),high);
      TrendPointChange(0,T6l,1,iTime(NULL,TimeFrame,0),low);
     }
   if(Trade&&Bid<low-GapStart*Point&&!ordersell)
     {
   
      wwe=OrderSend(NULL,OP_SELL,AccountBalance()/300,Bid,0,low+GapSL*Point,Bid-TP*Point,"",Magic,0,clrRed);
      Trade=false;
      ObjectSetInteger(0,T6h,OBJPROP_RAY_RIGHT,false);
      ObjectSetInteger(0,T6l,OBJPROP_RAY_RIGHT,false);
      TrendPointChange(0,T6l,1,iTime(NULL,TimeFrame,0),low);
      TrendPointChange(0,T6h,1,iTime(NULL,TimeFrame,0),high);
     }
  }
  }}}//}
    
//+------------------------------------------------------------------+
void check()
  {
   double hi=iHigh(NULL,TimeFrame,6);
   if(hi>iClose(NULL,TimeFrame,1)&&iHigh(NULL,TimeFrame,6)>iClose(NULL,TimeFrame,2)&&hi>iClose(NULL,TimeFrame,3)&&
      hi>iClose(NULL,TimeFrame,4)&&hi>iClose(NULL,TimeFrame,5)&&iLow(NULL,TimeFrame,6)<iClose(NULL,TimeFrame,1) &&
      iLow(NULL,TimeFrame,6)<iClose(NULL,TimeFrame,2) &&iLow(NULL,TimeFrame,6)<iClose(NULL,TimeFrame,3) &&
      iLow(NULL,TimeFrame,6)<iClose(NULL,TimeFrame,4) &&iLow(NULL,TimeFrame,6)<iClose(NULL,TimeFrame,5) &&
      Trade==false&&!orderbuy&&!ordersell)
     {
      high=iHigh(NULL,TimeFrame,6);
      low=iLow(NULL,TimeFrame,6);
      if(high-low<=MaxSizeCandle*Point&&high-low>=MinSizeCandle*Point)
        {
         T6h=DoubleToString(high)+IntegerToString(TimeDayOfYear(iTime(NULL,TimeFrame,6)));
         T6l=DoubleToString(low)+IntegerToString(TimeDayOfYear(iTime(NULL,TimeFrame,6)));
         TrendCreate(0,T6h,0,iTime(NULL,TimeFrame,6),high,iTime(NULL,TimeFrame,0),high,clrRed, STYLE_SOLID,1,false,false,true,true,0);
         TrendCreate(0,T6l,0,iTime(NULL,TimeFrame,6),low,iTime(NULL,TimeFrame,0),low,clrBlue,STYLE_SOLID,1,false,false,true,true,0);
         Trade=true;
        }
     }
   for(int i=0; i<OrdersHistoryTotal(); i++)
     {
      wwe=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      if(OrderMagicNumber()==Magic&&(OrderType()==OP_BUY||OrderType()==OP_SELL)&&OrderSymbol()==Symbol()&&OrderOpenTime()>=iTime(NULL,TimeFrame,0))
         Trade=false;
     }
  }
//+------------------------------------------------------------------+
void bs()
  {
   orderbuy=false;
   ordersell=false;
   for(int i=0; i<OrdersTotal(); i++)
     {
      wwe=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==Magic&&OrderType()==OP_BUY&&OrderSymbol()==Symbol())
         orderbuy=true;
      if(OrderMagicNumber()==Magic&&OrderType()==OP_SELL&&OrderSymbol()==Symbol())
         ordersell=true;
     }
  }
//+------------------------------------------------------------------+
void OnInit()
  {
  // Detect 3/5 digit brokers for Point and Slippage

if (Digits == 5 || Digits == 3)    // Adjust for five (5) digit brokers.
   {            
      pips2dbl = Point*10; pips2point = 10; pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*10;
   } 
   else 
   {    
      pips2dbl = Point;   pips2point = 1; pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*1;
   }
   
  
  
 //  -----------------------
   Trade=false;
  }
  
//+------------------------------------------------------------------+
bool TrendCreate(const long chart_ID=0,const string name="TrendLine",const int sub_window=0,datetime time1=0,double price1=0,
                 datetime time2=0,double price2=0,const color clr=clrRed,const ENUM_LINE_STYLE style=STYLE_SOLID,
                 const int width=1,const bool back=false,const bool selection=true,const bool ray_right=false,
                 const bool hidden=true,const long z_order=0)
  {
   ResetLastError();
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2))
     {
      Print(__FUNCTION__,
            ": failed to create a trend line! Error code = ",GetLastError());
      return(false);
     }
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool TrendPointChange(const long chart_ID=0,const string name="TrendLine",const int point_index=0,datetime time=0,
                      double price=0)
  {
   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   ResetLastError();
   if(!ObjectMove(chart_ID,name,point_index,time,price))
     {
      Print(__FUNCTION__,": failed to move the anchor point! Error code = ",GetLastError());
      return(false);
     }
   return(true);
  }
//+------------------------------------------------------------------+

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 ---