e-MAGIC_00800

Author: FinGeR aka Alexander Piechotta
Profit factor:
0.87

Here's a breakdown of what the script does, explained in a way that avoids technical jargon and focuses on the overall logic:

This script is designed to automatically place pending buy or sell orders in the market based on certain price movements. It essentially tries to anticipate where the price might go next.

Here's the basic process:

  1. Initialization: When the script starts, it sets up some initial values, like the lot size (the amount of currency to trade) and how far away the stop-loss (the level at which to automatically close a losing trade) and take-profit (the level at which to automatically close a winning trade) orders should be.

  2. Daily Check: Every day, the script looks at the previous day's price action.

  3. Order Management: It first deletes any pending orders (orders waiting to be triggered) that it previously placed.

  4. Parameter Setup Based on the previous day's high and low prices, it determines whether to look for a buying or selling opportunity. It calculates a key price level (FiboP) based on the difference between the high and low prices.

  5. Trading Logic:

    • It determines if the price is trending upwards or downwards based on the opening and closing prices.
    • Based on the trend it places a pending buy or sell limit order at the calculated key price level (FiboP). A buy limit order is placed if the script believes that after a short dip, the price will go up. A sell limit order is placed if the script believes that after a short rise, the price will go down.
    • The script also sets the stop-loss (to limit potential losses) and take-profit (to secure gains).
  6. Order Placement: The script tries to place the pending order (buy or sell) with the broker. If the order is successful, it may play a sound. If it fails, it tries again a few times, pausing between attempts.

  7. Trailing Stop: The script also includes a "trailing stop" feature. This means that as a trade moves in a profitable direction, the stop-loss level automatically adjusts to "trail" the price, locking in profits and further limiting potential losses.

In essence, this script is an automated system that analyzes previous day's price data to identify potential entry points for trades. It then places pending orders with pre-defined stop-loss and take-profit levels, and also adjust the stop-loss order to follow the price as it moves in a profitable direction.

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
8 Views
0 Downloads
0 Favorites
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);
                        }
                    }
                }
            }
        }
        
   }
   
   }
   
   


 
 



   

Profitability Reports

GBP/AUD Jul 2025 - Sep 2025
0.45
Total Trades 47
Won Trades 6
Lost trades 41
Win Rate 12.77 %
Expected payoff -9.00
Gross Profit 349.29
Gross Loss -772.29
Total Net Profit -423.00
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 2
Lost trades 3
Win Rate 40.00 %
Expected payoff -21071.04
Gross Profit 132.80
Gross Loss -105488.00
Total Net Profit -105355.20
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.68
Total Trades 52
Won Trades 10
Lost trades 42
Win Rate 19.23 %
Expected payoff -2.96
Gross Profit 332.90
Gross Loss -486.80
Total Net Profit -153.90
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.32
Total Trades 111
Won Trades 30
Lost trades 81
Win Rate 27.03 %
Expected payoff 5.69
Gross Profit 2593.36
Gross Loss -1961.43
Total Net Profit 631.93
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.91
Total Trades 109
Won Trades 24
Lost trades 85
Win Rate 22.02 %
Expected payoff -1.41
Gross Profit 1558.18
Gross Loss -1712.12
Total Net Profit -153.94
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.03
Total Trades 108
Won Trades 25
Lost trades 83
Win Rate 23.15 %
Expected payoff 0.28
Gross Profit 1253.68
Gross Loss -1223.06
Total Net Profit 30.62
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
1.11
Total Trades 116
Won Trades 31
Lost trades 85
Win Rate 26.72 %
Expected payoff 1.22
Gross Profit 1399.50
Gross Loss -1258.40
Total Net Profit 141.10
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
1.09
Total Trades 109
Won Trades 27
Lost trades 82
Win Rate 24.77 %
Expected payoff 1.60
Gross Profit 2019.80
Gross Loss -1845.00
Total Net Profit 174.80
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.81
Total Trades 106
Won Trades 18
Lost trades 88
Win Rate 16.98 %
Expected payoff -3.46
Gross Profit 1522.52
Gross Loss -1889.54
Total Net Profit -367.02
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
1.31
Total Trades 105
Won Trades 28
Lost trades 77
Win Rate 26.67 %
Expected payoff 5.60
Gross Profit 2487.09
Gross Loss -1899.12
Total Net Profit 587.97
-100%
-50%
0%
50%
100%

Comments