Platinum v0-2

Author: E Brand
Price Data Components
Series array that contains open prices of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reached
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
62.00 %
Total Trades 9
Won Trades 5
Lost trades 4
Win Rate 0.56 %
Expected payoff -66.44
Gross Profit 986.00
Gross Loss -1584.00
Total Net Profit -598.00
-100%
-50%
0%
50%
100%
Platinum v0-2
//+------------------------------------------------------------------+
//|                                                Platinum v0-2.mq4 |
//|                                                          E Brand |
//|                                         http://www.ebenbrand.com |
//+------------------------------------------------------------------+
#property copyright "E Brand"
#property link      "http://www.ebenbrand.com"

//---- input parameters

extern double    MaxReqSwing=90;
extern double    Margin=20;
extern double    DeadBand=20;
extern double    StopLoss=66;
extern double    TakeProfit=34;
extern double    MinLots=0.01;
extern double    MaxLots=10;
extern double    RiskFactor=0.075;
extern bool      SL_Reverse=false;
extern int       TriggerTime=17;
extern string    ExpirationTime="23:00";
extern int       magicno=888;

static int       LASTRUN;
static int       buy_orders_open=0;
static int       sell_orders_open=0;



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

//---- Alert if period is not equal to 5 minute charts
   if(Period() != PERIOD_H1)
      {
      Alert("Error - Chart period is <> 5 minutes.");
      }

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

   double yesterday_high=0;
   double yesterday_low=0;
   double yesterday_close=0;
   double maxdiff=0;
   double highdiff=0;
   double lowdiff=0;
   double stop=0;
   double TP=0;
   double lots=1;
   double price=0;
   int seed=0;
   int slip=5;
   int ticket=0;
   int i=0; // Counter


// Number of bars in previous day

   double prev_day_highs[24];
   double prev_day_lows[24];




   while((TimeDayOfWeek(Time[0])  > 0) && (TimeDayOfWeek(Time[0]) <6))
      {
      Comment("It's a trading day!!");
      if ((LASTRUN == Time[0]))
         {
         return(0);
         Comment("It's a no go, no new bar!!");
         }
      else
         {
         LASTRUN = Time[0];
         Comment("Now we check whether the trigger time has come up");
         if (TimeHour(Time[0]) != TriggerTime)
            return(0);
         }

      Print("We're now executing the main code!!");


//---- Get new daily prices

      ArrayCopySeries(prev_day_highs, MODE_HIGH, Symbol(), PERIOD_H1);
      ArrayCopySeries(prev_day_lows, MODE_LOW, Symbol(), PERIOD_H1);
      yesterday_close = iOpen(Symbol(), PERIOD_H1, 0);
      yesterday_high = prev_day_highs[ArrayMaximum(prev_day_highs, 24, 0)];
      yesterday_low = prev_day_lows[ArrayMinimum(prev_day_lows, 24, 0)];
Print("New daily stats : ", "Date : ", Month( ), "/", Day(), "Close ", yesterday_close, "  ", "High ", yesterday_high, "  ", "Low ", yesterday_low);

      maxdiff = yesterday_high - yesterday_low;
      highdiff = yesterday_high-yesterday_close;
      lowdiff = yesterday_close - yesterday_low;



// Check if there are open / pending Orders
      buy_orders_open = 0;
      sell_orders_open = 0;
      for (i=0; i<=OrdersTotal(); i++)
         {
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         if((OrderSymbol()==Symbol()) && (OrderMagicNumber() == magicno))
            {
            if((OrderType() == OP_BUY) || (OrderType() == OP_BUYSTOP))
               buy_orders_open = buy_orders_open + 1;
            if((OrderType() == OP_SELL) || (OrderType() == OP_SELLSTOP))
               sell_orders_open = sell_orders_open + 1;
            }
         }
Print("Buy orders = ", buy_orders_open, "   Sell orders = ", sell_orders_open);




//Buystop
      price = yesterday_high - (DeadBand/10000);
      stop = price - (StopLoss/10000);
      TP = price + (TakeProfit/10000);
      lots = NormalizeDouble((RiskFactor * AccountEquity() / (Ask+(DeadBand/20000))/1000), 1);


      if (((maxdiff) >= (MaxReqSwing/10000)) && (((highdiff) >= (Margin/10000)) && ((lowdiff) >= (Margin/10000))))
         {
         if(buy_orders_open==0)
            {
            ticket = OrderSend(Symbol(), OP_BUYSTOP, lots, price, slip, stop, TP, "Buy Order", magicno, StrToTime(ExpirationTime), Blue);
            Print("Buy =  ", price, "    lots = ", lots, "    Stop = ", stop, "    TP = ", TP, "    Order no = ", ticket);
            if(ticket<0)
               {
               Print("Buy Order failed with error #",GetLastError());
               ticket = 0;
               return(0);
               }
            }

         price = yesterday_low + (DeadBand/10000);
         stop = price + (StopLoss/10000);
         TP = price - (TakeProfit/10000);
         
         if(sell_orders_open==0)
            {
            ticket = OrderSend(Symbol(), OP_SELLSTOP, lots, price, slip, stop, TP, "Sell Order", magicno, StrToTime(ExpirationTime), Blue);
            Print("Sell =  ", price, "lots = ", lots, "    Stop = ", stop, "    TP = ", TP, "     Order no = ", ticket);
            if(ticket<0)
               {
               Print("Buy Order failed with error #",GetLastError());
               ticket = 0;
               return(0);
               }
            }
         }  
      } 
   return(0);
   }
//+------------------------------------------------------------------+

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