MACD Alberto Slow2

Orders Execution
It automatically opens orders when conditions are reached
Indicators Used
MACD HistogramMoving average indicator
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
31.00 %
Total Trades 100
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -1.15
Gross Profit 51.00
Gross Loss -166.00
Total Net Profit -115.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
41.00 %
Total Trades 97
Won Trades 21
Lost trades 76
Win Rate 0.22 %
Expected payoff -0.92
Gross Profit 63.00
Gross Loss -152.00
Total Net Profit -89.00
-100%
-50%
0%
50%
100%
MACD Alberto Slow2

extern double TakeProfit = 30; 
extern double StopLoss  =  20; 
extern double Lots = 0.1; 

//mia aggiunta 
int NumOrder ; 

//+------------------------------------------------------------------+ 
//|                                                                  | 
//+------------------------------------------------------------------+ 
int start() 
  { 

   double Macd_1, Macd_2, Macd_3, Macd_4, Ma_Quick, Ma_Slow; 
   bool Long_1, Long_2, Long, Short_1, Short_2, Short; 
   int cnt, ticket, total;
    

   if(Bars<100) 
     { 
      Print("bars less than 100"); 
      return(0);  
     } 
     
     if( isNewBar()){  NumOrder = 0;} 
      
   if(TakeProfit<10) 
     { 
      Print("TakeProfit less than 10"); 
      return(0);  // check TakeProfit 
     } 
// to simplify the coding and speed up access 
// data are put into internal variables 
   Macd_1 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,1); 
   Macd_2 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,2); 
   Macd_3 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,3); 
   Macd_4 = iMACD(NULL,0,3,20,9,PRICE_CLOSE,MODE_MAIN,4); 
   Ma_Quick = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0); 
   Ma_Slow  = iMA(NULL,0,65,0,MODE_EMA,PRICE_CLOSE,0);
   
   Long_1   = Macd_1 > Macd_2 && Macd_2 < Macd_3  && Ma_Quick > Ma_Slow && Macd_2 < 0 && Ask > High[1];
   Long_2   = Macd_2 > Macd_3 && Macd_3 < Macd_4  && Ma_Quick > Ma_Slow && Macd_3 < 0 && Ask > High[2] && High[1] < High[2];
   Long     = Long_1 || Long_2;
   Short_1  = Macd_1 < Macd_2 && Macd_2 > Macd_3  && Ma_Quick < Ma_Slow && Macd_2 > 0 && Bid < Low[1];
   Short_2  = Macd_2 < Macd_3 && Macd_3 > Macd_4  && Ma_Quick < Ma_Slow && Macd_3 > 0 && Bid < Low[2]  && Low[1] > Low[2];
   Short    = Short_1 || Short_2; 


// no opened orders identified 
      if(AccountFreeMargin()<(1000*Lots)) 
        { 
         Print("We have no money. Free Margin = ", AccountFreeMargin()); 
         return(0);  
        } 
        
        
// check for long position (BUY) possibility 
      if(Long) 
      {
       if(NumOrder == 0)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,NULL,Ask-StopLoss*Point,Ask+TakeProfit*Point,"macd sample",16384,0,Green); 
         if(ticket>0) 
           { 
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            { 
             Print("BUY order opened : ",OrderOpenPrice()); 
             NumOrder = 1; 
            } 
           } 
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        } 
      } 
     
// check for short position (SELL) possibility 
      if(Short)
        {           
        if(NumOrder == 0)
        {   
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopLoss*Point,Bid-TakeProfit*Point,"macd sample",16384,0,Red); 
         if(ticket>0) 
           { 
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
             { 
            Print("SELL order opened : ",OrderOpenPrice()); 
            NumOrder = 1; 
             } 
           } 
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        } 
      return(0);   
        }    
  } 
  
// the end. 

bool isNewBar() 
{ 
   static datetime lastbar=0; 
   datetime curbar = Time[0]; 
   if(lastbar!=curbar) 
   { 
   lastbar=curbar; 
      return (true); 
   } 
   else 
   { 
      return(false); 
   } 
} 

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