Price Impulse

Author: runik
Price Data Components
0 Views
0 Downloads
0 Favorites
Price Impulse
ÿþ//+------------------------------------------------------------------+

//|                       Price Impulse(barabashkakvn's edition).mq5 |

//|                                                            runik |

//|                                                  ngb2008@mail.ru |

//+------------------------------------------------------------------+

#property copyright "runik"

#property link      "ngb2008@mail.ru"

#property version   "1.000"

//---

#include <Trade\Trade.mqh>

#include <Trade\SymbolInfo.mqh>  

CTrade         m_trade;                      // trading object

CSymbolInfo    m_symbol;                     // symbol info object

//+------------------------------------------------------------------+

//| ENUM_COPY_TICKS                                                  |

//+------------------------------------------------------------------+

enum  ENUM_COPY_TICKS

  {

   TICKS_INFO=1,     // B>;L:> Bid 8 Ask 

   TICKS_TRADE=2,    // B>;L:> Last 8 Volume

   TICKS_ALL=-1,     // 2A5 B8:8

  };

//--- input parameters

input double   InpLots           = 0.1;      // Lots

input ushort   InpStopLoss       = 150;      // Stop Loss 

input ushort   InpTakeProfit     = 50;       // Take Profit 

input int      InpPoints         = 15;       // F5=0 4>;6=0 ?@>9B8 NNN ?C=:B>2

input uchar    InpTicks          = 15;       // 70 XXX B8:>2

input int      InpSleep          = 100;      // <8=8<0;L=0O ?0C70 <564C B@5940<8

//--- <0AA82K 4;O ?@85<0 B8:>2

MqlTick        tick_array_curr[];            // <0AA82 B8:>2 ?>;CG5==K9 =0 B5:CI5< B8:5

MqlTick        tick_array_prev[];            // <0AA28 B8:>2 ?>;CG5==K9 =0 ?@54K4CI5< B8:5

input ENUM_COPY_TICKS tick_flags=TICKS_INFO; // B8:8, 2K720==K5 87<5=5=8O<8 Bid 8/8;8 Ask

ulong          tick_from=0;                  // 5A;8 ?0@0<5B@ tick_from=0, B> >B40NBAO ?>A;54=85 tick_count B8:>2

uint           tick_count=15;                // :>;8G5AB2> B8:>2, :>B>@K5 =5>1E>48<> ?>;CG8BL 

//---

double         ExtStopLoss=0.0;

double         ExtTakeProfit=0.0;

double         ExtPoints=0.0;

bool           first_start=false;

long           last_trade_time=0;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

   if(!m_symbol.Name(Symbol())) // sets symbol name

      return(INIT_FAILED);



   tick_count+=InpTicks;               // 1C45< 70?@0H820BL "tick_count" + "70 XXX B8:>2"

   ExtStopLoss=InpStopLoss*Point();

   ExtTakeProfit=InpTakeProfit*Point();

   ExtPoints=InpPoints*Point();

   first_start=false;

//--- 70?@>A8< B8:8 (?5@2>5 70?>;=5=85)

   int copied=CopyTicks(Symbol(),tick_array_curr,tick_flags,tick_from,tick_count);

   if(copied!=tick_count)

      first_start=false;

   else

     {

      first_start=true;

      ArrayCopy(tick_array_prev,tick_array_curr);

     }

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---



  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//--- ?@>25@:0 =0 ?5@2K9 AB0@B

   int copied=-1;

   if(!first_start)

     {

      copied=CopyTicks(Symbol(),tick_array_curr,tick_flags,tick_from,tick_count);

      if(copied!=tick_count)

         first_start=false;

      else

        {

         first_start=true;

         ArrayCopy(tick_array_prev,tick_array_curr);

        }

     }

//--- 70?@>A8< B8:8

   copied=CopyTicks(Symbol(),tick_array_curr,tick_flags,tick_from,tick_count);

   if(copied!=tick_count)

      return;

   int index_new=-1;

   long last_time_msc=tick_array_prev[tick_count-1].time_msc;

   for(int i=(int)tick_count-1;i>=0;i--)

     {

      if(last_time_msc==tick_array_curr[i].time_msc)

        {

         index_new=i;

         break;

        }

     }

   if(index_new!=-1 && tick_array_curr[tick_count-1].time_msc-last_trade_time>InpSleep*1000)

     {

      int shift=(int)tick_count-1-index_new-InpTicks;   // A<5I5=85 2 B5:CI5< <0A825 B8:>2

      shift=(shift<0)?0:shift;

      if(tick_array_curr[tick_count-1].ask-tick_array_curr[shift].ask>ExtPoints)

        {

         int d=0;

         //--- >B:@K205< BUY

         double sl=(InpStopLoss==0)?0.0:tick_array_curr[tick_count-1].ask-ExtStopLoss;

         double tp=(InpTakeProfit==0)?0.0:tick_array_curr[tick_count-1].ask+ExtTakeProfit;

         m_trade.Buy(InpLots,m_symbol.Name(),tick_array_curr[tick_count-1].ask,

                     m_symbol.NormalizePrice(sl),

                     m_symbol.NormalizePrice(tp));

         last_trade_time=tick_array_curr[tick_count-1].time_msc;

        }

      else if(tick_array_curr[shift].bid-tick_array_curr[tick_count-1].bid>ExtPoints)

        {

         int d=0;

         //--- >B:@K205< SELL

         double sl=(InpStopLoss==0)?0.0:tick_array_curr[tick_count-1].bid-ExtStopLoss;

         double tp=(InpTakeProfit==0)?0.0:tick_array_curr[tick_count-1].bid+ExtTakeProfit;

         m_trade.Sell(InpLots,m_symbol.Name(),tick_array_curr[tick_count-1].bid,

                      m_symbol.NormalizePrice(sl),

                      m_symbol.NormalizePrice(tp));

         last_trade_time=tick_array_curr[tick_count-1].time_msc;

        }

     }

   ArrayCopy(tick_array_prev,tick_array_curr);

//---

  }

//+------------------------------------------------------------------+

//| TradeTransaction function                                        |

//+------------------------------------------------------------------+

void OnTradeTransaction(const MqlTradeTransaction &trans,

                        const MqlTradeRequest &request,

                        const MqlTradeResult &result)

  {

//---



  }

//+------------------------------------------------------------------+

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