130 lines
3.9 KiB
MQL5
130 lines
3.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| BoxEvalTrader |
|
|
//| Copyright 2018, MetaQuotes Software Corp. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
|
|
#property version "1.13.0"
|
|
|
|
#include <Trade\Trade.mqh>
|
|
#include <Generic\SortedMap.mqh>
|
|
|
|
#include "MTLibrary\MTUtils.mqh"
|
|
#include "MTLibrary\MTBox.mqh"
|
|
#include "MTLibrary\MTBalancer.mqh"
|
|
#include "MTLibrary\MTMonitor.mqh"
|
|
|
|
|
|
//ading a line
|
|
|
|
input group "General"
|
|
|
|
// Will be disable for now untili figure a better inlcussion method
|
|
input int StopLoss = 0;
|
|
input int TakeProfit = 150;
|
|
|
|
input group "Box Signal"
|
|
input int box_height = 100;
|
|
input int box_lenght = 5;
|
|
input double winner_multiplier = 0.70;
|
|
input double loser_multiplier = 0.30;
|
|
|
|
|
|
input group "MultiTrade Balancer"
|
|
input BalancerTrigger mt_balancer = mtb_volume;
|
|
input int Position_Trigger = 10;
|
|
input double Volume_Trigger = 0.40;
|
|
input double Volume_unBalancer = 0.20;
|
|
input bool EnableTradeOnLimits = true;
|
|
|
|
|
|
double Ask;
|
|
double Bid;
|
|
|
|
DBox box;
|
|
MTBalancer balancer;
|
|
MTMonitor monitor;
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
box.Init(box_height, box_lenght, loser_multiplier, winner_multiplier);
|
|
balancer.balancer_type = mt_balancer;
|
|
balancer.positions_trigger = Position_Trigger;
|
|
balancer.volume_difference = Volume_Trigger;
|
|
balancer.enable_trade_on_limit = EnableTradeOnLimits;
|
|
balancer.setBaseVolume();
|
|
balancer.setBalancingVolume(Volume_unBalancer);
|
|
monitor.Init();
|
|
return 0;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
|
|
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
|
|
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);
|
|
double price = NormalizeDouble((Ask + Bid) / 2, _Digits);
|
|
|
|
if(box.isFirstBox())
|
|
{
|
|
box.doFirstBox(price,Ask,Bid);
|
|
}
|
|
|
|
|
|
box.PrintTheBox(price, Ask, Bid);
|
|
|
|
if(!box.shouldUpdateBox())
|
|
{
|
|
if(monitor.BoxCanPlacePosition())
|
|
{
|
|
|
|
if(box.shouldGoLong(price) && (monitor.CanPlacePositionInDirection(true) && monitor.CanPlacePositionInDirectionByVolume(true)))
|
|
{
|
|
int vol_mult = monitor.getPositionTracker().getLastPositionsLong();
|
|
place_a_long(Ask,TakeProfit, vol_mult,StopLoss);
|
|
//place_a_short(Bid, TakeProfit, vol_mult, StopLoss);
|
|
monitor.addPositionToTracker(true);
|
|
box.UpdateBox(price,Ask,Bid,UPDATE_LONG_W);
|
|
}
|
|
else
|
|
if(box.shouldGoShort(price) && (monitor.CanPlacePositionInDirection(false) && monitor.CanPlacePositionInDirectionByVolume(false)))
|
|
{
|
|
int vol_mult = monitor.getPositionTracker().getLastPositionsShort();
|
|
place_a_short(Bid, TakeProfit, vol_mult, StopLoss);
|
|
//place_a_long(Ask,TakeProfit, vol_mult,StopLoss);
|
|
monitor.addPositionToTracker(false);
|
|
box.UpdateBox(price,Ask,Bid, UPDATE_SHORT_W);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
box.reduceBoxLife();
|
|
|
|
}
|
|
else
|
|
{
|
|
box.UpdateBox(price, Ask, Bid);
|
|
}
|
|
|
|
|
|
if(monitor.BalancerCanPlacePosition())
|
|
{
|
|
Print("Entering for Balancing" );
|
|
balancer.doBalancing(Ask,Bid,TakeProfit);
|
|
}
|
|
|
|
monitor.AssessClosingLimits();
|
|
}
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|