VisualOpenOrderWithMM

Author: Itso
Orders Execution
It automatically opens orders when conditions are reached
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
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%
VisualOpenOrderWithMM
//+------------------------------------------------------------------+
//|                                        VisualOpenOrderWithMM.mq4 |
//|                                                             Itso |
//|                                                      itso@dir.bg |
//+------------------------------------------------------------------+
#property copyright "Itso"
#property link      "itso@dir.bg"
#property show_inputs
#include <stdlib.mqh>

extern double Risk = 0.05;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
   double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
   double Step = MarketInfo(Symbol(), MODE_LOTSTEP);

   double StopLoss = WindowPriceOnDropped();
   double MoneyRisk = AccountFreeMargin() * Risk;
   double TickValue = MarketInfo(Symbol(), MODE_TICKVALUE);

   double PointLoss;
   int cmd;
   double price;
   if(Ask>StopLoss)
   {
      //Open Long
      PointLoss = (Ask - StopLoss) / Point;
      cmd = OP_BUY;
      price = Ask;
   }
   else
   {
      //Open Short
      PointLoss = (StopLoss - Bid) / Point;
      cmd = OP_SELL;
      price = Bid;
   }

   double LotsRough = MoneyRisk / (TickValue * PointLoss);
   if(LotsRough<MinLot)
   {
      Print("Error. You don\'t have enough money!");
      return(0);
   }
   
   double Lots = MaxLot;
   for(double CheckedLot=MinLot; CheckedLot<=MaxLot; CheckedLot+=Step)
   {
      if(CheckedLot>LotsRough)
      {
         Lots = CheckedLot - Step;
         break;
      }
   }
   
   Print("Lots=",Lots);
   
   int ticket = OrderSend(Symbol(), cmd, Lots, price, 3, StopLoss, 0);
   if (ticket<0)
   {
      Print("Error: ", ErrorDescription(GetLastError()));
   }
//----
   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 ---