e-MAGIC_00800

Author: FinGeR aka Alexander Piechotta
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
90.00 %
Total Trades 50
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -0.93
Gross Profit 441.40
Gross Loss -487.80
Total Net Profit -46.40
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
83.00 %
Total Trades 53
Won Trades 10
Lost trades 43
Win Rate 0.19 %
Expected payoff -2.74
Gross Profit 693.50
Gross Loss -838.50
Total Net Profit -145.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
28.00 %
Total Trades 46
Won Trades 4
Lost trades 42
Win Rate 0.09 %
Expected payoff -7.31
Gross Profit 132.70
Gross Loss -469.00
Total Net Profit -336.30
-100%
-50%
0%
50%
100%
e-MAGIC_00800
//+------------------------------------------------------------------+
//|                                                    e-MAGIC 00800 |
//|                                                                  |
//| Last Update 23.01.07                                             |
//+------------------------------------------------------------------+

#property copyright "FinGeR aka Alexander Piechotta"
#property link      "5one51@googlemail.com"

#define MAGIC 00800

extern double Lots = 0.1;
extern double  TrailingStop=0;
double max=50;
double  StopLoss;
double  TakeProfit;

string Name_Expert   = "e-MAGIC 00800";
bool   UseSound      = False;       
string NameFileSound = "expert.wav"; 
bool   ShowComment   = True;        


int Slippage        = 4;      
int NumberOfTry     = 7;    
int PauseAfterError = 21;     


color clOpenBuy   = LightBlue;
color clOpenSell  = LightCoral;
color clCloseBuy  = Blue;
color clCloseSell = Red;

int  Curr;  
datetime  PrevTime;
double FiboP;
double FiboL,FiboH ;

#include <stdlib.mqh>

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

int init()
  {

return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

TrailingPositions(); 

if (PrevTime==iTime(NULL,1440,0))return(0); 
    PrevTime=iTime(NULL,1440,0);
    
DeleteAllOrders();
InitParameters();
OpenPositions();

return(0);

}
//+------------------------------------------------------------------+

void OpenPosition(int op, double ldStop, double ldTake) {
  color  clOpen;
  int    err, it, ticket;
  string lsComm=GetCommentForOrder();

  if (op==OP_BUYLIMIT) clOpen=clOpenBuy; else clOpen=clOpenSell;
 
  for (it=1; it<=NumberOfTry; it++) {
    while (!IsTradeAllowed()) Sleep(5000);
    RefreshRates();
   
    FiboP=NormalizeDouble(FiboP, Digits);
    ldStop=NormalizeDouble(ldStop, Digits);
    ldTake=NormalizeDouble(ldTake, Digits);
    ticket=OrderSend(Symbol(),op,Lots,FiboP,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpen);
    if (ticket>0) {
      if (UseSound) PlaySound(NameFileSound); break;
    } else {
      err=GetLastError();
      Print("Error(",err,") opening position: ",ErrorDescription(err),", try ",it);
      Sleep(1000*PauseAfterError);
    }
  }
}


string GetNameTF(int TimeFrame) {
	switch (TimeFrame) {
		case PERIOD_MN1: return("Monthly");
		case PERIOD_W1:  return("Weekly");
		case PERIOD_D1:  return("Daily");
		case PERIOD_H4:  return("H4");
		case PERIOD_H1:  return("H1");
		case PERIOD_M30: return("M30");
		case PERIOD_M15: return("M15");
		case PERIOD_M5:  return("M5");
		case PERIOD_M1:  return("M1");
		default:		     return("UnknownPeriod");
	}
}



string GetCommentForOrder() {
  return(Name_Expert+" "+GetNameTF(Period()));
}


void OpenPositions() {
  double ldStop=0, ldTake=0;
  StopLoss = FiboL;
  TakeProfit = FiboH;
  int bs=GetTradeSignal();
  

   if (bs>0) {
      if (StopLoss!=0) ldStop=StopLoss;
      if (TakeProfit!=0) ldTake=TakeProfit;
      OpenPosition(OP_BUYLIMIT, ldStop, ldTake);

    }
    if (bs<0) {
      if (StopLoss!=0) ldStop=StopLoss;
      if (TakeProfit!=0) ldTake=TakeProfit;
      OpenPosition(OP_SELLLIMIT, ldStop, ldTake);
      
    }
  
}



int GetTradeSignal() {
  int bs=0;
    
  if (Curr<0) bs=-1;
  if (Curr>0) bs=1;
 
return(bs);
}



void InitParameters() {
Curr=0;
double O = iOpen(NULL,1440,1);
double C = iClose(NULL,1440,1);
double H = iHigh(NULL,1440,1);
double L = iLow(NULL,1440,1);

if ( (H-L)<max*Point )return(0);

if(O < C)
               {
                FiboL = L;
                FiboH = H;
                Curr = 1;
               }
               else
               {
                  FiboL = H;
                  FiboH = L;
                  Curr = -1;
               }
               
               FiboP = FiboL + (FiboH - FiboL)*0.236;
              }




void DeleteAllOrders() {
  bool fd;
  for (int i=OrdersTotal()-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderMagicNumber()==MAGIC ) {
        if (OrderSymbol()==Symbol()) {
          if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP) {
            fd=OrderDelete(OrderTicket());
            if (fd && UseSound) PlaySound(NameFileSound);
          }
        }
      }
    }
  }
}





void TrailingPositions() {
        for(int i=0;i<OrdersTotal();i++)
   {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        
        if(OrderMagicNumber()!=MAGIC)
            continue;
       
        if(OrderType()<=OP_SELL &&OrderSymbol()==Symbol())
        {
            if(OrderType()==OP_BUY&&OrderSymbol()==Symbol())
            {
               if(TrailingStop>0)
               {
                    if(Bid-OrderOpenPrice()>(TrailingStop*Point))
                    {
                        if(OrderStopLoss()<(Bid-TrailingStop*Point))
                        {
                            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Green);
                        }
                    }
               }
                
            }
            if(OrderType()==OP_SELL&&OrderSymbol()==Symbol())
            {
  
                if(TrailingStop>0)
                {
                    if(OrderOpenPrice()-Ask>(TrailingStop*Point))
                    {
                        if(OrderStopLoss()>(Ask+TrailingStop*Point)||(OrderStopLoss()==0))
                        {
                            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Green);
                        }
                    }
                }
            }
        }
        
   }
   
   }
   
   


 
 



   

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