Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Lesson 9 Buy sell stop Order - expert for MetaTrader 5

Views:
5694
Rating:
(4)
Published:
2024.05.28 21:21
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

I. Main function

1. Using condition buy or sell base on price action.

2. Auto caculate lot size

3. Auto trailling stop by ATR.

4. Backtest result

II. Main tick function

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 {
   if(OpenBar(Symbol())) 
   {
   OrderManaging();
 // Candle declaration
 double High[],Low[],open[],close[];
 ArraySetAsSeries(High,true);ArraySetAsSeries(Low,true);ArraySetAsSeries(close,true);ArraySetAsSeries(open,true);
 CopyHigh(Symbol(),timeframe,0,1000,High);
 CopyLow(Symbol(),timeframe,0,1000,Low);
 CopyOpen(_Symbol,timeframe,0,100,open);
 CopyClose(_Symbol,timeframe,0,100,close);
 
// Highest high and lowest low declaration
int highest= ArrayMaximum(High,HL_shift,HL_period);
int lowest= ArrayMinimum(Low,HL_shift,HL_period); 

double  HH= High[highest];
//Drawline(" Kháng Cự ", clrRed,HH);
double  LL= Low[lowest];
//Drawline(" hỗ trợ ", clrBlue,LL);

// Moving average declaration
CopyBuffer(Handle_MA,0,0,100,MA_Filter);
ArraySetAsSeries(MA_Filter,true);

 // Atr declaration
 ArraySetAsSeries(atr,true); CopyBuffer(hand_atr,0,0,50,atr);
 
 // Volume and MA_volume array buffe
 ArraySetAsSeries(Volume,true); ArraySetAsSeries(MA_volume,true);
 CopyBuffer(handle_volume,0,0,50,Volume);
 CopyBuffer(handle_MA_volume,0,0,50,MA_volume);
//+------------------------------------------------------------------+
//|   Broker parameter                                               |
//+------------------------------------------------------------------+     
double point = SymbolInfoDouble(_Symbol,SYMBOL_POINT);
double ask= SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid= SymbolInfoDouble(_Symbol,SYMBOL_BID);
double spread=ask-bid;
double stoplevel= (int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
int freezerlevel= (int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL); 
 
 // Count bjuy and count sell
 int count_buy=0; int count_sell=0;
 count_position(count_buy,count_sell,atr);

 // Main condition for buy and sell
    if(count_buy==0  )
    
     {      
       if( High[highest] > MA_Filter[highest]   )
       
        {
         double  entryprice= HH;
         double  sl        = LL;
         double  tp        = entryprice   +TP_factor*atr[1];
         double lotsize    = calculate_lotsize(sl,entryprice);
        if( entryprice>ask+stoplevel && entryprice-sl>stoplevel && tp-entryprice>stoplevel)
         {
          trade.BuyStop(lotsize,entryprice,_Symbol,sl,tp,ORDER_TIME_DAY);
        
         }
       }
     }
    if(count_sell==0)
     {  
     if( Low[lowest] < MA_Filter[lowest])   
        {
         double  entryprice= LL;
         double  sl        = HH;
         double  tp        = entryprice   -TP_factor*atr[1];
         double lotsize    = calculate_lotsize(sl,entryprice);
         if( entryprice<bid-stoplevel && sl-entryprice>stoplevel && entryprice-tp>stoplevel)
         {
         trade.SellStop(lotsize,entryprice,_Symbol,sl,tp,ORDER_TIME_DAY);
         }
        }
     }
   
  }
 
  }


Lesson 7 Price action Ket hop Volume VSA Lesson 7 Price action Ket hop Volume VSA

This is a lesson on trading using price action combined with volume.

Trailing stop tutorial using ATR indicator Trailing stop tutorial using ATR indicator

Trailing stop tutorial using ATR indicator

Beginner Programming: Moving Average Crossover with and without Martingale functionality Beginner Programming: Moving Average Crossover with and without Martingale functionality

Moving averages are useless. In fact, some argue that the best way to lose money for a beginner are MA-Price crossover strategies. But is it possible to make it work?

MovingAverages.mqh Part I by Wiliam210 MovingAverages.mqh Part I by Wiliam210

This indicator shows you how to use native functions SimpleMA(), ExponentialMA(), SmoothedMA(), LinearWeightedMA which are in the MovingAverages.mqh library in the includes directory