You didn't post a topic yet. Let us show you how to make your first topic and upload your favorite forex robot. Guide me

Skip to forum content

Login with Facebook

Login with Username and Password!

     Username:       Password:  Login

Register  |  Forgot Password?

 

The latest topics with attached files (Forex robots, Forex Indicators, etc..)

Forums in this category with details of Replies, Views, last post

EA martingle bot

by Muhammad Allif Bin Ahmad

SZ_Scalper free

by Holger Bläsner

new member is here

by ShakEel Ashiq


Pages 1

You must login or register to post a reply

RSS

Posts: 2
Please rate this topic
Current rating: 0
Votes: 0

Embed topic to your site

Universal One Min Scalper - MQ4 file (expert advisor)

Topic: Universal One Min Scalper - MQ4 file (expert advisor)

This is a scalper that can be used to trade on the One Minute charts of any asset class.

//+------------------------------------------------------------------+
//                        DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//
//                   Copyright ©2017, https://mt4talk.com
//                     MT4talk Expert Advisor Generator
//                        https://mt4talk.com/eagenerator/
//
// THIS EXPERT ADVISOR (EA) HAS BEEN GENERATED USING MT4talk EA GENERATOR. 
// 
// Disclaimer: This EA is provided to you "AS-IS", and MT4talk disclaims any warranty
// or liability obligations to you of any kind. 
//
// FREE EA LICENSE
// This EA is provided to you for free of charge! You can share this EA on any website or any forums. 
//
// CFTC RULE 4.41
// HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED 
// RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-
// OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS, 
// IN GENERAL, ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING 
// MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.
//
// U.S. Government Required Disclaimer.
// Commodity Futures Trading Commission Futures and Options trading has large potential rewards, but also large potential risk. 
// You must be aware the risks and be willing to accept them in order to invest in the futures and options markets. 
// Don't trade with money you can't afford to lose. This is neither a solicitation nor an offer to Buy/Sell futures or options.
// No representation is being made that any account will or is likely to achieve profits or losses similar 
// to those discussed on this website. The past performance of any trading system or methodology is not necessarily 
// indicative of future results.
//
// USE THIS EA AT YOUR OWN RISK. 
//
//                      DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//+------------------------------------------------------------------+

#property copyright "Copyright 2017"
#property link      "https://mt4talk.com"
#property version   "1.00"
#property strict
extern double Lotsize=0.1;
extern int Magic_Number=12345;
extern int Max_Nr_Of_Trades=1;
extern int Max_Nr_Of_Buy_Trades=1;
extern bool Hidden=false;
extern double Stop_Loss=0;
extern double Take_Profit=0;
extern double Trailing_Stop=0; 
extern bool    Close_opposit_signal=false;    
extern int Max_Nr_Of_Sell_Trades=0; 
extern bool DayFilter=false; 
extern bool TimeFilter=false;
 
double Risk=0;

double Martingale_Value=0;

bool FixSL=0;
int Money_Management=0;

int cntmartin=0;
double ts=0;
double be=0;
double sl,tp;
int mp;
datetime lasttrade;


 

 

int OnInit() 
 
{ 
    mp=1;
    if (Digits==5 || Digits==3) mp=10; 
    lasttrade=TimeCurrent();
    cntmartin=0;
    
    if (Money_Management==1)   
    {
       Stop_Loss=Stop_Loss/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Take_Profit=Take_Profit/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Break_Even=Break_Even/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Trailing_Stop=Trailing_Stop/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
    }

    //---
    return(INIT_SUCCEEDED);

} 

 
void OnDeinit(const int reason)
 
{} 

 
void OnTick()
{
    bool TradeAllow=false;
    bool buy_signal=false;
    bool sell_signal=false;
    double sl;
    double tp;
    double lotsize;
    
 
    buy_signal=GetSignal(OP_BUY);
    sell_signal=GetSignal(OP_SELL);
 
    //---       
    if((CloseSignal(OP_BUY)) ||
        (sell_signal && Close_opposit_signal))
    {
      CloseOrders(OP_BUY);
    }
    if((CloseSignal(OP_SELL)) ||
        (buy_signal && Close_opposit_signal))
    {
      CloseOrders(OP_SELL);
    }
 
    if((Max_Nr_Of_Trades>0 && GetNrOfTrades(6)<Max_Nr_Of_Trades)||
        Max_Nr_Of_Trades==0)
    {
        if((Max_Nr_Of_Buy_Trades>0 && GetNrOfTrades(OP_BUY)<Max_Nr_Of_Trades)||
            Max_Nr_Of_Trades==0)
        {
            if(buy_signal)
            {
                if (Money_Management==2)
                {
                    double entry;
        
                    entry=MarketInfo(Symbol(),MODE_ASK);
                    if(FixSL)
                    {    
                        sl=NormalizeDouble(entry-Stop_Loss*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        Lotsize=NormalizeDouble(CalcLotsize(Symbol(),entry,sl,Risk),2);
                        tp=NormalizeDouble(entry+CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    else
                    {
                        sl=NormalizeDouble(entry-CalcDistance(Stop_Loss,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        tp=NormalizeDouble(entry+CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    
                }
                   
                   
                if (GetLastProfit(lotsize)<0 && Martingale_Type>0)
                {
                    Lotsize=lotsize;
                    cntmartin++;
                }
                else
                {
                    cntmartin=0;
                }
                  
                if (Martingale_Type==1)//Increment
                {
                    Lotsize+=Martingale_Value;
                }
                        
                if (Martingale_Type==2)//Multipli
                {
                     Lotsize*=Martingale_Value;
                }
                OpenOrder(OP_BUY);
            }
        }
        if((Max_Nr_Of_Sell_Trades>0 && GetNrOfTrades(OP_SELL)<Max_Nr_Of_Sell_Trades)||
            Max_Nr_Of_Sell_Trades==0)
        {
            if(sell_signal)
            {
                if (Money_Management==2)
                {
                    double entry;
                    entry=MarketInfo(Symbol(),MODE_BID);
                    if(FixSL)
                    {
                        sl=NormalizeDouble(entry+Stop_Loss*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));
                        Lotsize=NormalizeDouble(CalcLotsize(Symbol(),entry,sl,Risk),2);
                        tp=NormalizeDouble(entry-CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    else
                    {
                        sl=NormalizeDouble(entry+CalcDistance(Stop_Loss,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        tp=NormalizeDouble(entry-CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                }
                
                
                if (GetLastProfit(lotsize)<0 && Martingale_Type>0)
                {
                    Lotsize=lotsize;
                    cntmartin++;
                }
                else
                {
                    cntmartin=0;
                }
                  
                if (Martingale_Type==1)//Increment
                {
                    Lotsize+=Martingale_Value;
                }
                        
                if (Martingale_Type==2)//Multipli
                {
                     Lotsize*=Martingale_Value;
                }
                OpenOrder(OP_SELL);
            }
        }
    }
}
       
 
 
bool GetSignal(int type)
{
    bool b=false;
     
 
    if(type==OP_BUY)
    {
 
            if(iMomentum(Symbol(),0,14,0,0)>=iMomentum(Symbol(),5,14,0,0))
            {
               b=true;
            }
        } 
 
    if(type==OP_SELL)
    {
            if(iMomentum(Symbol(),0,14,0,0)<=iMomentum(Symbol(),5,14,0,0))
            {
               b=true;
            }
        } 
 
    return(b);
} 
 
bool CloseSignal(int type)
{
    bool b=false;
     
 
    if(type==OP_BUY)
    {
            if(Ask>=iRSI(Symbol(),5,9,0,0))
            {
               b=true;
            }
        } 
 
    if(type==OP_SELL)
    {
            if(Bid<=iRSI(Symbol(),5,9,0,0))
            {
               b=true;
            }
        } 
 
    return(b);
}
 
void OpenOrder(int type)
{
   int ticket=-1;
   int err=0;
  
    if(type==OP_BUY)
    {
        ticket = OrderSend(Symbol(), OP_BUY, Lotsize, MarketInfo(Symbol(), MODE_ASK), 10, 0, 0,"", Magic_Number);       
        if(ticket<0)
        {
            err=GetLastError();
            //Print ('Error!. Cannot Open BUY, failed with error : ',err);
        }
        else
        {
            if(Money_Management<2)
            {
                sl=NormalizeDouble(MarketInfo(Symbol(), MODE_ASK)-Stop_Loss*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
                tp=NormalizeDouble(MarketInfo(Symbol(), MODE_ASK)+Take_Profit*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
            }
            OrderModify(ticket, MarketInfo(Symbol(), MODE_ASK), sl, tp,0);//open price=MarketInfo(Symbol(), MODE_ASK)
        }
    }

    if(type==OP_SELL)
    {
        ticket = OrderSend(Symbol(), OP_BUY, Lotsize, MarketInfo(Symbol(), MODE_BID), 10, 0, 0,"", Magic_Number);       
        if(ticket<0)
        {
            err=GetLastError();
            //Print ('Error!. Cannot Open BUY, failed with error : ',err);
        }
        else
        {
            if(Money_Management<2)
            {
                sl=NormalizeDouble(MarketInfo(Symbol(), MODE_BID)+Stop_Loss*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
                tp=NormalizeDouble(MarketInfo(Symbol(), MODE_BID)-Take_Profit*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
            }
            OrderModify(ticket, MarketInfo(Symbol(), MODE_BID), sl, tp,0);//open price=MarketInfo(Symbol(), MODE_ASK)
        }
    }
}
 
void CloseOrders(int type)
{
   int total  = OrdersTotal();
   for (int i = total-1 ; i >=0 ; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && 
        OrderMagicNumber() == Magic_Number && 
        OrderSymbol() == Symbol() && 
        type==OrderType()) 
        {
            switch(OrderType())
            {
                case OP_BUY:
                {
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),10);
                    break;  
                }
                                  
                case OP_SELL:
                {
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),10);
                    break;
                }
            }             
        }
    }
}
 
bool IsNewBar()
{
    if (lasttrade<iTime(Symbol(),0,0))
    {
        lasttrade=iTime(Symbol(),0,0);
        return (true);
    }
    return (false);
}
int GetNrOfTrades(int type)
{
   int t=0;
   
   int total = OrdersTotal();
   int count;
   if(type==OP_BUY || type==OP_SELL)
   {
       for(count = total - 1; count >= 0; count--)
       {
          if(!OrderSelect(count, SELECT_BY_POS, MODE_TRADES)) continue;
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number && OrderType()==type)
          {
             t++;
          }
       }
       return (t);
   }
   else if(type==6)
   {
       for(count = total - 1; count >= 0; count--)
       {
          if(!OrderSelect(count, SELECT_BY_POS, MODE_TRADES)) continue;
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number)
          {
             t++;
          }
       }
       return (t);
   }
   return(t);
}
    
 
double CalcLotsize(string symbol,double entry, double sl,double risk)
{
   
   double qty,riskm,dist; 
   dist=MathAbs(entry-sl)/MarketInfo(symbol,MODE_POINT);
   riskm=AccountBalance()*risk/100;
   
   qty=riskm/(dist*MarketInfo(symbol,MODE_TICKVALUE));  
   return( NormalizeDouble(qty,2) );
}
    
 
void Trailing(double Trailing_Stop)
{
  int err;
   double sl = 0;
   bool result;
   
   //
   sl = OrderStopLoss();
   if(OrderType() == OP_BUY)
   {
      if((MarketInfo(Symbol(),MODE_BID) > (OrderOpenPrice() + Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT))) )
      {                        
         
         if(OrderStopLoss() == 0) sl = MarketInfo(Symbol(),MODE_BID) - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT);
         if(OrderStopLoss() != 0 && MarketInfo(Symbol(),MODE_BID) >= OrderStopLoss() + Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT)) sl = MarketInfo(Symbol(),MODE_BID) - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT);
         while(IsTradeContextBusy()) Sleep(100);
         if(sl > OrderStopLoss())
         {
            ResetLastError();
            result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
            //
            if (result)
            {               
               Print("Trailing Stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(OrderStopLoss(), MarketInfo(Symbol(),MODE_DIGITS)), "; Bid = ", DoubleToStr(MarketInfo(Symbol(),MODE_BID), MarketInfo(Symbol(),MODE_DIGITS)));
            }
            else
            {
               err = GetLastError();
               Print("Error!. Trailing Stop #", OrderTicket(), " order modify failed with error(",err,")");
            }
         }
      }
   }//if(OrderType() == OP_BUY)
   //
   if(OrderType() == OP_SELL)
   {
      
      if((MarketInfo(Symbol(),MODE_ASK) < (OrderOpenPrice() - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT))))
      {
         
         if(OrderStopLoss() == 0) sl = MarketInfo(Symbol(),MODE_ASK) + (Trailing_Stop*mp)*MarketInfo(Symbol(),MODE_POINT);
         if(OrderStopLoss() != 0 && MarketInfo(Symbol(),MODE_ASK) <= OrderStopLoss() - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT)) sl = MarketInfo(Symbol(),MODE_ASK) + (Trailing_Stop*mp)*MarketInfo(Symbol(),MODE_POINT);
         while(IsTradeContextBusy()) Sleep(100);
         if(sl < OrderStopLoss())
         {
            ResetLastError();
            result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
            //
            if (result)
            {
               Print("Trailing Stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Ask = ", DoubleToStr(MarketInfo(Symbol(),MODE_ASK), MarketInfo(Symbol(),MODE_DIGITS)));
            }
            else
            {
               err = GetLastError();
               Print("Error!. Trailing Stop #", OrderTicket(), " order modify failed with error(",err,")");
            }
         }
      }
   }
}
    
 
void ManageTrades()
{
   int t=OrdersTotal();
   for(int i=t-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number)
         {
            if (!Hidden)
            {
                if (Money_Management==2)
                {
                    ts=CalcDistance(Trailing_Stop,OrderLots());//OrderLots
                    be=CalcDistance(Break_Even,OrderLots()); 
                }
                else
                {
                    ts=Trailing_Stop;
                    be=Break_Even;
                }
                
                if (Break_Even>0)
                {
                    BreakEven(be);
                }
                if (Trailing_Stop>0)
                {
                    Trailing(ts);
                }
            }
           
         
         }
      }
   }//for end
}
    
 
    
void BreakEven(double Break_Even)
{
   bool result;
   double sl;
   int err;
   //
   ResetLastError();
   if(OrderType() == OP_BUY)
   {
       if(OrderStopLoss() >= OrderOpenPrice()) return;
       
       if (MarketInfo(Symbol(),MODE_BID) >= OrderOpenPrice() + Break_Even*mp*MarketInfo(Symbol(),MODE_POINT))
       {
         sl= OrderOpenPrice() ;
         while(IsTradeContextBusy()) Sleep(100);
         result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
         if (result)
         {
            Print("Break Even stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Bid = ", DoubleToStr(MarketInfo(Symbol(),MODE_BID), MarketInfo(Symbol(),MODE_DIGITS)));
         }
         else
         {
            err = GetLastError();
            Print("Error!. Break Even #", OrderTicket(), " order modify failed with error(",err,")");
         }
       }
   }
   //
   if (OrderType() == OP_SELL) 
   {
       if (OrderStopLoss() <= OrderOpenPrice() && OrderStopLoss() != 0) return;
       
       if (MarketInfo(Symbol(),MODE_ASK) <= OrderOpenPrice() - Break_Even*mp*MarketInfo(Symbol(),MODE_POINT))
       {
         sl = OrderOpenPrice() ;
         while(IsTradeContextBusy()) Sleep(100);
         result = OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
         if (result)
         {           
            Print("Break Even stop updated: # ", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Ask = ", DoubleToStr(MarketInfo(Symbol(),MODE_ASK), MarketInfo(Symbol(),MODE_DIGITS)));
         }
         else
         {
            err = GetLastError();
            Print("Error!. Break Even #", OrderTicket(), " order modify failed with error(",err,")");
         }
       }
   }
}
    
 
double CalcDistance(double risk, double lotsize)
{
   risk=AccountBalance()*risk/100;
   return (risk/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/lotsize);
}

 
double GetLastProfit(double& lotsize)
{
   int t=OrdersTotal();
   double p=0;
   datetime mt=0;
   
   for (int i=t-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number && OrderCloseTime()>mt)
         {
            mt=OrderCloseTime();
            p=OrderProfit();
            lotsize=OrderLots();
         }
      }
   }
   
   return (p);
}
Post's attachments

13711_Universal One Min Scalper.mq4 16.09 kb, 32 downloads since 2018-06-13 

Share

 Top 5 MT4talk Forum Topics!

UPDATE: This robot now makes huge money! $24,512 profit in 10 days! 

Very Profitable EA, No Martingale Strategy!

Really Profitable EA 50-100% monthly

10K $ to 750 Million $ in 10 Year 69% Win. Should I put this EA Live?

$$$ - Copy this trades automatically and earn big daily profit.  

Re: Universal One Min Scalper - MQ4 file (expert advisor)

kamalkumar_j wrote:

This is a scalper that can be used to trade on the One Minute charts of any asset class.

//+------------------------------------------------------------------+
//                        DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//
//                   Copyright ©2017, https://mt4talk.com
//                     MT4talk Expert Advisor Generator
//                        https://mt4talk.com/eagenerator/
//
// THIS EXPERT ADVISOR (EA) HAS BEEN GENERATED USING MT4talk EA GENERATOR. 
// 
// Disclaimer: This EA is provided to you "AS-IS", and MT4talk disclaims any warranty
// or liability obligations to you of any kind. 
//
// FREE EA LICENSE
// This EA is provided to you for free of charge! You can share this EA on any website or any forums. 
//
// CFTC RULE 4.41
// HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED 
// RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-
// OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS, 
// IN GENERAL, ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING 
// MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.
//
// U.S. Government Required Disclaimer.
// Commodity Futures Trading Commission Futures and Options trading has large potential rewards, but also large potential risk. 
// You must be aware the risks and be willing to accept them in order to invest in the futures and options markets. 
// Don't trade with money you can't afford to lose. This is neither a solicitation nor an offer to Buy/Sell futures or options.
// No representation is being made that any account will or is likely to achieve profits or losses similar 
// to those discussed on this website. The past performance of any trading system or methodology is not necessarily 
// indicative of future results.
//
// USE THIS EA AT YOUR OWN RISK. 
//
//                      DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//+------------------------------------------------------------------+

#property copyright "Copyright 2017"
#property link      "https://mt4talk.com"
#property version   "1.00"
#property strict
extern double Lotsize=0.1;
extern int Magic_Number=12345;
extern int Max_Nr_Of_Trades=1;
extern int Max_Nr_Of_Buy_Trades=1;
extern bool Hidden=false;
extern double Stop_Loss=0;
extern double Take_Profit=0;
extern double Trailing_Stop=0; 
extern bool    Close_opposit_signal=false;    
extern int Max_Nr_Of_Sell_Trades=0; 
extern bool DayFilter=false; 
extern bool TimeFilter=false;
 
double Risk=0;

double Martingale_Value=0;

bool FixSL=0;
int Money_Management=0;

int cntmartin=0;
double ts=0;
double be=0;
double sl,tp;
int mp;
datetime lasttrade;


 

 

int OnInit() 
 
{ 
    mp=1;
    if (Digits==5 || Digits==3) mp=10; 
    lasttrade=TimeCurrent();
    cntmartin=0;
    
    if (Money_Management==1)   
    {
       Stop_Loss=Stop_Loss/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Take_Profit=Take_Profit/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Break_Even=Break_Even/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
       Trailing_Stop=Trailing_Stop/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/Lotsize;
    }

    //---
    return(INIT_SUCCEEDED);

} 

 
void OnDeinit(const int reason)
 
{} 

 
void OnTick()
{
    bool TradeAllow=false;
    bool buy_signal=false;
    bool sell_signal=false;
    double sl;
    double tp;
    double lotsize;
    
 
    buy_signal=GetSignal(OP_BUY);
    sell_signal=GetSignal(OP_SELL);
 
    //---       
    if((CloseSignal(OP_BUY)) ||
        (sell_signal && Close_opposit_signal))
    {
      CloseOrders(OP_BUY);
    }
    if((CloseSignal(OP_SELL)) ||
        (buy_signal && Close_opposit_signal))
    {
      CloseOrders(OP_SELL);
    }
 
    if((Max_Nr_Of_Trades>0 && GetNrOfTrades(6)<Max_Nr_Of_Trades)||
        Max_Nr_Of_Trades==0)
    {
        if((Max_Nr_Of_Buy_Trades>0 && GetNrOfTrades(OP_BUY)<Max_Nr_Of_Trades)||
            Max_Nr_Of_Trades==0)
        {
            if(buy_signal)
            {
                if (Money_Management==2)
                {
                    double entry;
        
                    entry=MarketInfo(Symbol(),MODE_ASK);
                    if(FixSL)
                    {    
                        sl=NormalizeDouble(entry-Stop_Loss*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        Lotsize=NormalizeDouble(CalcLotsize(Symbol(),entry,sl,Risk),2);
                        tp=NormalizeDouble(entry+CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    else
                    {
                        sl=NormalizeDouble(entry-CalcDistance(Stop_Loss,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        tp=NormalizeDouble(entry+CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    
                }
                   
                   
                if (GetLastProfit(lotsize)<0 && Martingale_Type>0)
                {
                    Lotsize=lotsize;
                    cntmartin++;
                }
                else
                {
                    cntmartin=0;
                }
                  
                if (Martingale_Type==1)//Increment
                {
                    Lotsize+=Martingale_Value;
                }
                        
                if (Martingale_Type==2)//Multipli
                {
                     Lotsize*=Martingale_Value;
                }
                OpenOrder(OP_BUY);
            }
        }
        if((Max_Nr_Of_Sell_Trades>0 && GetNrOfTrades(OP_SELL)<Max_Nr_Of_Sell_Trades)||
            Max_Nr_Of_Sell_Trades==0)
        {
            if(sell_signal)
            {
                if (Money_Management==2)
                {
                    double entry;
                    entry=MarketInfo(Symbol(),MODE_BID);
                    if(FixSL)
                    {
                        sl=NormalizeDouble(entry+Stop_Loss*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));
                        Lotsize=NormalizeDouble(CalcLotsize(Symbol(),entry,sl,Risk),2);
                        tp=NormalizeDouble(entry-CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                    else
                    {
                        sl=NormalizeDouble(entry+CalcDistance(Stop_Loss,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS));     
                        tp=NormalizeDouble(entry-CalcDistance(Take_Profit,Lotsize)*mp*Point(),(int)MarketInfo(Symbol(),MODE_DIGITS)); 
                    }
                }
                
                
                if (GetLastProfit(lotsize)<0 && Martingale_Type>0)
                {
                    Lotsize=lotsize;
                    cntmartin++;
                }
                else
                {
                    cntmartin=0;
                }
                  
                if (Martingale_Type==1)//Increment
                {
                    Lotsize+=Martingale_Value;
                }
                        
                if (Martingale_Type==2)//Multipli
                {
                     Lotsize*=Martingale_Value;
                }
                OpenOrder(OP_SELL);
            }
        }
    }
}
       
 
 
bool GetSignal(int type)
{
    bool b=false;
     
 
    if(type==OP_BUY)
    {
 
            if(iMomentum(Symbol(),0,14,0,0)>=iMomentum(Symbol(),5,14,0,0))
            {
               b=true;
            }
        } 
 
    if(type==OP_SELL)
    {
            if(iMomentum(Symbol(),0,14,0,0)<=iMomentum(Symbol(),5,14,0,0))
            {
               b=true;
            }
        } 
 
    return(b);
} 
 
bool CloseSignal(int type)
{
    bool b=false;
     
 
    if(type==OP_BUY)
    {
            if(Ask>=iRSI(Symbol(),5,9,0,0))
            {
               b=true;
            }
        } 
 
    if(type==OP_SELL)
    {
            if(Bid<=iRSI(Symbol(),5,9,0,0))
            {
               b=true;
            }
        } 
 
    return(b);
}
 
void OpenOrder(int type)
{
   int ticket=-1;
   int err=0;
  
    if(type==OP_BUY)
    {
        ticket = OrderSend(Symbol(), OP_BUY, Lotsize, MarketInfo(Symbol(), MODE_ASK), 10, 0, 0,"", Magic_Number);       
        if(ticket<0)
        {
            err=GetLastError();
            //Print ('Error!. Cannot Open BUY, failed with error : ',err);
        }
        else
        {
            if(Money_Management<2)
            {
                sl=NormalizeDouble(MarketInfo(Symbol(), MODE_ASK)-Stop_Loss*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
                tp=NormalizeDouble(MarketInfo(Symbol(), MODE_ASK)+Take_Profit*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
            }
            OrderModify(ticket, MarketInfo(Symbol(), MODE_ASK), sl, tp,0);//open price=MarketInfo(Symbol(), MODE_ASK)
        }
    }

    if(type==OP_SELL)
    {
        ticket = OrderSend(Symbol(), OP_BUY, Lotsize, MarketInfo(Symbol(), MODE_BID), 10, 0, 0,"", Magic_Number);       
        if(ticket<0)
        {
            err=GetLastError();
            //Print ('Error!. Cannot Open BUY, failed with error : ',err);
        }
        else
        {
            if(Money_Management<2)
            {
                sl=NormalizeDouble(MarketInfo(Symbol(), MODE_BID)+Stop_Loss*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
                tp=NormalizeDouble(MarketInfo(Symbol(), MODE_BID)-Take_Profit*mp*MarketInfo(Symbol(),MODE_POINT), MarketInfo(Symbol(),MODE_DIGITS));
            }
            OrderModify(ticket, MarketInfo(Symbol(), MODE_BID), sl, tp,0);//open price=MarketInfo(Symbol(), MODE_ASK)
        }
    }
}
 
void CloseOrders(int type)
{
   int total  = OrdersTotal();
   for (int i = total-1 ; i >=0 ; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && 
        OrderMagicNumber() == Magic_Number && 
        OrderSymbol() == Symbol() && 
        type==OrderType()) 
        {
            switch(OrderType())
            {
                case OP_BUY:
                {
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),10);
                    break;  
                }
                                  
                case OP_SELL:
                {
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),10);
                    break;
                }
            }             
        }
    }
}
 
bool IsNewBar()
{
    if (lasttrade<iTime(Symbol(),0,0))
    {
        lasttrade=iTime(Symbol(),0,0);
        return (true);
    }
    return (false);
}
int GetNrOfTrades(int type)
{
   int t=0;
   
   int total = OrdersTotal();
   int count;
   if(type==OP_BUY || type==OP_SELL)
   {
       for(count = total - 1; count >= 0; count--)
       {
          if(!OrderSelect(count, SELECT_BY_POS, MODE_TRADES)) continue;
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number && OrderType()==type)
          {
             t++;
          }
       }
       return (t);
   }
   else if(type==6)
   {
       for(count = total - 1; count >= 0; count--)
       {
          if(!OrderSelect(count, SELECT_BY_POS, MODE_TRADES)) continue;
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number)
          {
             t++;
          }
       }
       return (t);
   }
   return(t);
}
    
 
double CalcLotsize(string symbol,double entry, double sl,double risk)
{
   
   double qty,riskm,dist; 
   dist=MathAbs(entry-sl)/MarketInfo(symbol,MODE_POINT);
   riskm=AccountBalance()*risk/100;
   
   qty=riskm/(dist*MarketInfo(symbol,MODE_TICKVALUE));  
   return( NormalizeDouble(qty,2) );
}
    
 
void Trailing(double Trailing_Stop)
{
  int err;
   double sl = 0;
   bool result;
   
   //
   sl = OrderStopLoss();
   if(OrderType() == OP_BUY)
   {
      if((MarketInfo(Symbol(),MODE_BID) > (OrderOpenPrice() + Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT))) )
      {                        
         
         if(OrderStopLoss() == 0) sl = MarketInfo(Symbol(),MODE_BID) - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT);
         if(OrderStopLoss() != 0 && MarketInfo(Symbol(),MODE_BID) >= OrderStopLoss() + Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT)) sl = MarketInfo(Symbol(),MODE_BID) - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT);
         while(IsTradeContextBusy()) Sleep(100);
         if(sl > OrderStopLoss())
         {
            ResetLastError();
            result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
            //
            if (result)
            {               
               Print("Trailing Stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(OrderStopLoss(), MarketInfo(Symbol(),MODE_DIGITS)), "; Bid = ", DoubleToStr(MarketInfo(Symbol(),MODE_BID), MarketInfo(Symbol(),MODE_DIGITS)));
            }
            else
            {
               err = GetLastError();
               Print("Error!. Trailing Stop #", OrderTicket(), " order modify failed with error(",err,")");
            }
         }
      }
   }//if(OrderType() == OP_BUY)
   //
   if(OrderType() == OP_SELL)
   {
      
      if((MarketInfo(Symbol(),MODE_ASK) < (OrderOpenPrice() - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT))))
      {
         
         if(OrderStopLoss() == 0) sl = MarketInfo(Symbol(),MODE_ASK) + (Trailing_Stop*mp)*MarketInfo(Symbol(),MODE_POINT);
         if(OrderStopLoss() != 0 && MarketInfo(Symbol(),MODE_ASK) <= OrderStopLoss() - Trailing_Stop*mp*MarketInfo(Symbol(),MODE_POINT)) sl = MarketInfo(Symbol(),MODE_ASK) + (Trailing_Stop*mp)*MarketInfo(Symbol(),MODE_POINT);
         while(IsTradeContextBusy()) Sleep(100);
         if(sl < OrderStopLoss())
         {
            ResetLastError();
            result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
            //
            if (result)
            {
               Print("Trailing Stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Ask = ", DoubleToStr(MarketInfo(Symbol(),MODE_ASK), MarketInfo(Symbol(),MODE_DIGITS)));
            }
            else
            {
               err = GetLastError();
               Print("Error!. Trailing Stop #", OrderTicket(), " order modify failed with error(",err,")");
            }
         }
      }
   }
}
    
 
void ManageTrades()
{
   int t=OrdersTotal();
   for(int i=t-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS))
      {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number)
         {
            if (!Hidden)
            {
                if (Money_Management==2)
                {
                    ts=CalcDistance(Trailing_Stop,OrderLots());//OrderLots
                    be=CalcDistance(Break_Even,OrderLots()); 
                }
                else
                {
                    ts=Trailing_Stop;
                    be=Break_Even;
                }
                
                if (Break_Even>0)
                {
                    BreakEven(be);
                }
                if (Trailing_Stop>0)
                {
                    Trailing(ts);
                }
            }
           
         
         }
      }
   }//for end
}
    
 
    
void BreakEven(double Break_Even)
{
   bool result;
   double sl;
   int err;
   //
   ResetLastError();
   if(OrderType() == OP_BUY)
   {
       if(OrderStopLoss() >= OrderOpenPrice()) return;
       
       if (MarketInfo(Symbol(),MODE_BID) >= OrderOpenPrice() + Break_Even*mp*MarketInfo(Symbol(),MODE_POINT))
       {
         sl= OrderOpenPrice() ;
         while(IsTradeContextBusy()) Sleep(100);
         result = OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
         if (result)
         {
            Print("Break Even stop updated: #", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Bid = ", DoubleToStr(MarketInfo(Symbol(),MODE_BID), MarketInfo(Symbol(),MODE_DIGITS)));
         }
         else
         {
            err = GetLastError();
            Print("Error!. Break Even #", OrderTicket(), " order modify failed with error(",err,")");
         }
       }
   }
   //
   if (OrderType() == OP_SELL) 
   {
       if (OrderStopLoss() <= OrderOpenPrice() && OrderStopLoss() != 0) return;
       
       if (MarketInfo(Symbol(),MODE_ASK) <= OrderOpenPrice() - Break_Even*mp*MarketInfo(Symbol(),MODE_POINT))
       {
         sl = OrderOpenPrice() ;
         while(IsTradeContextBusy()) Sleep(100);
         result = OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(sl, MarketInfo(Symbol(),MODE_DIGITS)), OrderTakeProfit(), 0, CLR_NONE);
         if (result)
         {           
            Print("Break Even stop updated: # ", OrderTicket(), "; SL = ", DoubleToStr(sl, MarketInfo(Symbol(),MODE_DIGITS)), "; Ask = ", DoubleToStr(MarketInfo(Symbol(),MODE_ASK), MarketInfo(Symbol(),MODE_DIGITS)));
         }
         else
         {
            err = GetLastError();
            Print("Error!. Break Even #", OrderTicket(), " order modify failed with error(",err,")");
         }
       }
   }
}
    
 
double CalcDistance(double risk, double lotsize)
{
   risk=AccountBalance()*risk/100;
   return (risk/MarketInfo(Symbol(),MODE_TICKVALUE)/mp/lotsize);
}

 
double GetLastProfit(double& lotsize)
{
   int t=OrdersTotal();
   double p=0;
   datetime mt=0;
   
   for (int i=t-1;i>=0;i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number && OrderCloseTime()>mt)
         {
            mt=OrderCloseTime();
            p=OrderProfit();
            lotsize=OrderLots();
         }
      }
   }
   
   return (p);
}

Thank you !)
But sorry, it doesn't work.
6 Errors and 27 warnings by compiling:

https://gyazo.com/0c9ada963a9d392a01e6f5e558308087

Share

Posts: 2

Pages 1

You must login or register to post a reply

Last Posts

  • 25/06: Broker a medium
  • 25/06: Emotion Controlling
  • 25/06: safe Forex Robot
  • 24/06: UPDATE: This robot now makes huge money! $24,512 profit in 10 days!
  • 24/06: zhao signal
  • 24/06: Regular Forex Trading.
  • 23/06: Broker is one of the most reliable support system
  • 23/06: Best broker for beginners?
  • 23/06: Profitable Stepping Stone EA
  • 23/06: To choose.
  • 23/06: Automated Trading System
  • 22/06: TrillionPipsEA
  • 22/06: BBMA indicators 1
  • 22/06: HELLO
  • 21/06: Assar Ultra©™ High Frequency Forex Scalping in 2018
  • 21/06: Investing money.
  • 21/06: EA martingle bot
  • 20/06: This robot made me over $20,000.
  • 20/06: Demo is essential
  • 20/06: SZ_Scalper free
  • 20/06: For the beginners
  • 20/06: forex thunerbolt indicator
  • 19/06: Aggressor3_Great EA
  • 19/06: new member is here
  • 18/06: Does anyone have QT Indicator?
  • 18/06: Really Profitable EA 50-100% monthly
  • 17/06: cashflow - MQ4 file (expert advisor)
  • 16/06: My EA ichimoku
  • 16/06: EA LAU albuquerque - MQ4 file (expert advisor)
  • 16/06: Non-Lag Inverse Fisher of RSX indicator
  • 16/06: Ubat 5.0
  • 16/06: Blessing 3
  • 15/06: Afraid of losing money
  • 15/06: Trading decision after analysis
  • 15/06: Hey guy free EA for your test
  • Hot Topics

  • ASSAR v8 (1042)
  • Scalper_v5 (free) (720)
  • A highly profitable Ea (465)
  • FX Magic Robot - Verified Live Working 3/13/17 (458)
  • 2000 pips daily (451)
  • ASSAR V9 (Trend Breakout Edition) 2017 Expert Advisor (417)
  • spartan bolt V6 (414)
  • Assar_03_EA (391)
  • ASSARV11 [EXCLUSIVE] ACTIVE MEMBERS ONLY! (274)
  • Forex Earth Robot (249)
  • Trade-Arbitrage EA (248)
  • xmt scalper (227)
  • Forex Math EA free for Mt4 (180)
  • Super Signal Scalping Profit Statement (178)
  • Rabbit3 £100 start Zero to Hero Updated EA (167)
  • Fracture 7.4.0 (156)
  • high profit EA (151)
  • SCALPER PALING JOSS EA is a Holy Grail (150)
  • New to forex? (148)
  • Ilan Expert Advisor for Metatrader 4 (136)
  • EA SmartAssTrade. (133)
  • Monster Profit Forex Robot (123)
  • WayGrow EA 1.7 (111)
  • scalperstarkpro downoad free (price 90 dollars) (92)
  • FX Magic Robot (91)
  • IceFX TraderAgent Pro EA v2.5.1 (86)
  • Profitable GBPJPY EA (true results) (85)
  • Unbelievable EA (83)
  • Hedge Expert Advisor (63)
  • 100 pips profits trading (63)
  • Good EA 2017. Free !!! (63)
  • Magic Fx Formula indicator-V2 (61)
  • Best Indicator That No Repaint!!! (61)
  • hello (60)
  • BAR EA V5.1 (60)

  • NOTE: Hacked or other illegal versions of copyrighted forex robots are highly prohibited on MT4talk.com. If you upload any illegal version of any copyrighted forex robot, your forum account will be banned. No exceptions.

    Forum statistics

    • Total number of registered users: 19,729
    • Newest registered user: Byron Padilla
    • Total number of topics: 10,991
    • Total number of posts: 36,385

    Online users: 2,083 guests, 142 Members:

    8965556, Abdul Amirudin, adiyantoepm75, admin, alejoelchimpan, alesnetusil, amggunasekara, Andreas Holz, andydrae67, atanu.sarkar3, atef10364, axel7969, basnakhu, BENEX, blessing.baloyi03, bng7222, bolamajek, charity03, cjams247, coachklso, davbene74, dduu2261, denicmg074, Donnie Drajat, dule, Enrique Lafuente, Erhan Bircan, Expert2103, findel147, fxpro62, fxvnpro, gericson2, giampi9800, gjmrichardson, global168168, gordontan, Grigoryev.MV, GRTrader, Guillermo A. Vera Tapia, Hans, hendrikwong, henkvdm76, henroo, Howard Hamilton, huangjiang64, hussain.tradeexpress, inthecape, janreichen, jcorp.life, jiradpantananon, jlhtrader, Jordan Pritchett, Jorge Martinez, Jose Carlos de Oliveira, josino, jozmik, Junior Vix, Kabelo Collen Molokwe, kamalkumar_j, kamenn, kashif_raza, kasun, khangala05, khmerltd, kleberleal, kwazinkosi30, lonewolf8506, lucaasus68, Lucas Alonso, lyoung4472, machs_nochmal, makseem, Manuel Adv, Marais, marinho7, markvanbastien, Martin Batmala, martinsucer, maxheadroom, Mina Ibrahim, mohansundar961981, Mohd Nizam Maoc, mr.ifham2, mt4talk, multicoms, Myanmar River, nelsonli, nemaste, neri03, Nesto Tee Reyes, Neville Carr, nvcuongmpi, oaheco, outlier, Ozzmann, pablopretkus, paisanubon, palexis479, patrykolejnik512, pauljfitzpatrick, phumelela.mbili, Polow Lcd, prince1344, PROtrader001, pschultz, ptctodo, Pump Man, R-Juggernaut Solomon, rad1958, ramin, Reagan Kawuma, Rey David Chuba Chibuzor, Ricardo Potes Sunio, Rogger Ladislau, romelferdous, rondad, roslycyber, RSIHeaven, sa12345, savelahu, sbuzz, Silva1, simonkoen, smonphone17, spojka, stockshare, strangersenemy@gmail.com, sunny7day, Tasos Karas, tehi.scouter, Thanny Dayly Fx, ummadikanth, vjaichidambaram, waschut, why, Yannick Bonyoma, yuvaraja, Zaher Qattan, Zhao Fung, ป. ปุญณ์, สนธิชัย บอย สุวรรณปักษิน, แจ็ค สี่ จี

     


    Copyright MT4talk.com Forum Rules - Privacy Policy.