199 lines
19 KiB
MQL5
199 lines
19 KiB
MQL5
#property copyright "Copyright 2023, M & Q Investment Group"
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
#include <trade/trade.mqh>
|
|
CTrade trade;
|
|
//-------------------------------------------OVEROPTIMIZED VERSION AFTER 1. TESTING -------------
|
|
|
|
input double TrigPDif = 0.00005;
|
|
input double LotS = 1.0;
|
|
input int ExpiryTime = 120;
|
|
input double TickToleranceUpPercent = 10;
|
|
input double TickToleranceDownPercent = 80;
|
|
input int HowmanyCandleTickVolumes = 2;
|
|
input double TickToleranceMinMaxPuffer = 0.0001;
|
|
input int TickToleranceSafetyswitch = 20;
|
|
input double TicktoleranceYellowFallPercinDecimal = 0.5;
|
|
|
|
input double RuleMinimumTPSLValue = 0.0001;
|
|
|
|
input double PufferDistance = 0.0001;
|
|
|
|
input string Opentime = "07:30:00";
|
|
input string CloseTime = "23:00";
|
|
|
|
long TickVolumes[];
|
|
|
|
double bid0 = 0;
|
|
double accountbalancebeginning;
|
|
double accountprofit;
|
|
|
|
int TickToleranceDown;
|
|
int TickToleranceUp;
|
|
int TickTolerancePause;
|
|
int TicktoleranceYellowFall;
|
|
|
|
int OnInit(){
|
|
|
|
accountbalancebeginning = AccountInfoDouble(ACCOUNT_BALANCE);
|
|
//OrderinAction = false;
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
void OnTick(){
|
|
|
|
//DETERMINING TIMEFRAME
|
|
datetime opentimenow = StringToTime(Opentime);
|
|
datetime closetimenow = StringToTime(CloseTime);
|
|
datetime currenttime = TimeCurrent();
|
|
if(currenttime > opentimenow && currenttime < closetimenow){
|
|
|
|
|
|
//DETERMINE TICKTOLERANCE AND YELLOW STEIGUNG
|
|
ArrayResize(TickVolumes,HowmanyCandleTickVolumes);
|
|
ArraySetAsSeries(TickVolumes,true);
|
|
CopyTickVolume(_Symbol,PERIOD_CURRENT,0,HowmanyCandleTickVolumes,TickVolumes);
|
|
//----DEGBUGGING
|
|
//Print(TickVolumes[0]," ",TickVolumes[1]," ",TickVolumes[2]," ");
|
|
|
|
long ToleranceTicksSum = 0;
|
|
for(int i = 0; i < HowmanyCandleTickVolumes; i++){
|
|
ToleranceTicksSum = ToleranceTicksSum + TickVolumes[i];
|
|
}
|
|
//----DEGBUGGING
|
|
//Print("TickSum: ",ToleranceTicksSum);
|
|
|
|
if(ToleranceTicksSum < TickToleranceSafetyswitch){TickToleranceDown = 20; TickTolerancePause = 0; TickToleranceUp = 3; TicktoleranceYellowFall = 10;}
|
|
else{
|
|
TickToleranceDown = NormalizeDouble(ToleranceTicksSum * (TickToleranceDownPercent / 100),0);
|
|
TickToleranceUp = NormalizeDouble((ToleranceTicksSum - TickToleranceDown) *(TickToleranceUpPercent / 100),0);
|
|
TickTolerancePause = NormalizeDouble(ToleranceTicksSum - TickToleranceUp - TickToleranceDown,0);
|
|
TicktoleranceYellowFall = NormalizeDouble(ToleranceTicksSum * TicktoleranceYellowFallPercinDecimal ,0);
|
|
}
|
|
//----DEGBUGGING
|
|
//Print("TickToleranceDown: ",TickToleranceDown,"TickToleranceUp: ",TickToleranceUp,"TickTolerancePause: ",TickTolerancePause,"TicktoleranceYellowFall: ",TicktoleranceYellowFall);
|
|
|
|
//GET PINK AMA VALUES
|
|
double PinkAMAPriceArray[];
|
|
int PinkAMADefinition = iAMA (_Symbol,_Period,1,1,20,0,PRICE_CLOSE);
|
|
ArraySetAsSeries(PinkAMAPriceArray,true);
|
|
//AMA DEF, one line, current candle, 3 candles, store result
|
|
CopyBuffer(PinkAMADefinition,0,0,TickToleranceDown + TickTolerancePause + TickToleranceUp + 100,PinkAMAPriceArray);
|
|
double PinkAMACurrentValue = NormalizeDouble(PinkAMAPriceArray[0],6);
|
|
//----DEGBUGGING
|
|
//Print("PinkAMA Size: ",TickToleranceDown + TickTolerancePause + TickToleranceUp + 100,"Values: ",PinkAMAPriceArray[0],PinkAMAPriceArray[1],PinkAMAPriceArray[2],PinkAMAPriceArray[TickToleranceDown + TickTolerancePause + TickToleranceUp + 99]);
|
|
|
|
//GET YELLWOW AMA VALUES
|
|
double YellAMAPriceArray[];
|
|
int YellAMADefinition = iAMA (_Symbol,_Period,2,5,1,0,PRICE_CLOSE);
|
|
ArraySetAsSeries(YellAMAPriceArray,true);
|
|
//AMA DEF, one line, current candle, 3 candles, store result
|
|
CopyBuffer(YellAMADefinition,0,0,TickToleranceDown + TickTolerancePause+ TickToleranceUp + 100,YellAMAPriceArray);
|
|
double YellAMACurrentValue = NormalizeDouble(YellAMAPriceArray[0],6);
|
|
//----DEGBUGGING
|
|
//Print("YellAMA Size: ",TickToleranceDown + TickTolerancePause + TickToleranceUp + 100,"Values: ",YellAMAPriceArray[0],YellAMAPriceArray[1],YellAMAPriceArray[2],YellAMAPriceArray[TickToleranceDown + TickTolerancePause + TickToleranceUp + 99]);
|
|
|
|
//GET RED AMA VALUES
|
|
double RedAMAPriceArray[];
|
|
int RedAMADefinition = iAMA (_Symbol,_Period,5,2,30,0,PRICE_CLOSE);
|
|
ArraySetAsSeries(RedAMAPriceArray,true);
|
|
//AMA DEF, one line, current candle, 3 candles, store result
|
|
CopyBuffer(RedAMADefinition,0,0,TickToleranceDown + TickTolerancePause + TickToleranceUp + 100,RedAMAPriceArray);
|
|
double RedAMACurrentValue = NormalizeDouble(RedAMAPriceArray[0],6);
|
|
//----DEGBUGGING
|
|
//Print("RedAMA Size: ",TickToleranceDown + TickTolerancePause + TickToleranceUp + 100,"Values: ",RedAMAPriceArray[0],RedAMAPriceArray[1],RedAMAPriceArray[2],RedAMAPriceArray[TickToleranceDown + TickTolerancePause + TickToleranceUp + 99]);
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
|
|
//APPROVING TICKTOLERANCE VALUES
|
|
int YellTickTolUPMinInt = ArrayMinimum(YellAMAPriceArray,0,TickToleranceUp);
|
|
int PinkTickTolUPMax = ArrayMaximum(PinkAMAPriceArray,0,TickToleranceUp);
|
|
|
|
//OLD METHOD WITH TOLERANCE CHECK DOWN PINK YELLOW
|
|
/*int YellTickTolDownMaxInt = ArrayMaximum(YellAMAPriceArray,TickToleranceUp + TickTolerancePause - 1, TickToleranceDown);
|
|
int PinkTickTolDownMinInt = ArrayMinimum(PinkAMAPriceArray, TickToleranceUp + TickTolerancePause - 1, TickToleranceDown);*/
|
|
|
|
int PinkRedPufferDistanceCounter = 0;
|
|
for(int i = TickToleranceUp + TickTolerancePause; i < TickToleranceUp + TickTolerancePause + TickToleranceDown; i++){
|
|
|
|
if(RedAMAPriceArray[i] + PufferDistance < PinkAMAPriceArray[i]){
|
|
PinkRedPufferDistanceCounter = PinkRedPufferDistanceCounter + 1;
|
|
}
|
|
}
|
|
//----DEGBUGGING
|
|
Print(/*"YellTickTolDownMaxInt: ",YellTickTolDownMaxInt,*/
|
|
"YellTickTolUPMinInt: ",YellTickTolUPMinInt,
|
|
/*"PinkTickTolDownMinInt: ",PinkTickTolDownMinInt,*/
|
|
"PinkTickTolUPMax: ",PinkTickTolUPMax);
|
|
|
|
bool TicktoleranceApproved = false;
|
|
if( //OLD METHOD WITH TOLERANCE CHECK DOWN PINK YELLOW
|
|
//YellAMAPriceArray[YellTickTolDownMaxInt] + TickToleranceMinMaxPuffer < PinkAMAPriceArray[PinkTickTolDownMinInt] &&
|
|
YellAMAPriceArray[YellTickTolUPMinInt] - TickToleranceMinMaxPuffer > PinkAMAPriceArray[PinkTickTolUPMax] &&
|
|
PinkRedPufferDistanceCounter == TickToleranceDown){
|
|
|
|
TicktoleranceApproved = true;
|
|
}
|
|
//----DEGBUGGING
|
|
Print(//"YellTickTolDownMaxInt: ",YellAMAPriceArray[YellTickTolDownMaxInt],
|
|
//"\nPinkTickTolDownMinInt: ",PinkAMAPriceArray[PinkTickTolDownMinInt],
|
|
"\nYellTickTolUPMinInt: ",YellAMAPriceArray[YellTickTolUPMinInt] ,
|
|
"\nPinkTickTolUPMax: ",PinkAMAPriceArray[PinkTickTolUPMax]);
|
|
if(TicktoleranceApproved){Print("----- TicktoleranceApproved ----");}
|
|
|
|
|
|
//APPROVING IF YELLOW FALLS
|
|
double YellowFallsSum = 0;
|
|
bool YellowFallsApproved = false;
|
|
for(int i = 0; i < TickToleranceUp; i++){
|
|
|
|
YellowFallsSum = YellowFallsSum + YellAMAPriceArray[i] - YellAMAPriceArray[i+1];
|
|
}
|
|
if(YellowFallsSum >= 0){
|
|
YellowFallsApproved = true;
|
|
}
|
|
//--------------------------------DEBUGGING--------------------------------
|
|
if(YellowFallsApproved){Print("----- YellowFallsApproved ----");}
|
|
|
|
|
|
|
|
|
|
|
|
//SET THE ORDER
|
|
bid0 = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
|
|
double PufferPrice = RedAMACurrentValue + PufferDistance;
|
|
double InvalidStopProhibitorline = RuleMinimumTPSLValue + PufferDistance + RedAMACurrentValue;
|
|
|
|
if(/*TicktoleranceApproved == true &&*/ YellowFallsApproved == true && YellAMACurrentValue > PufferPrice && bid0 > InvalidStopProhibitorline && PositionsTotal() == 0 && OrdersTotal() == 0){
|
|
|
|
Print("----- TRADETRIGGER AUSGELÖST ----");
|
|
double TrigP = bid0 - TrigPDif;
|
|
double TP = RedAMACurrentValue;
|
|
double SL = bid0 + (bid0 - RedAMACurrentValue);
|
|
datetime OrderExpTime = TimeCurrent() + ExpiryTime;
|
|
trade.SellStop(LotS,TrigP,_Symbol,SL,TP,ORDER_TIME_SPECIFIED,OrderExpTime);
|
|
|
|
Print("Bidprice: ", bid0,
|
|
"\n Current Pink: ", PinkAMACurrentValue,
|
|
"\n Current Yellow: ", YellAMACurrentValue,
|
|
"\n Current Red: ", RedAMACurrentValue);
|
|
}
|
|
|
|
|
|
|
|
// DISPLAY OF VALUES ON CHART
|
|
double accountbalance = AccountInfoDouble(ACCOUNT_BALANCE);
|
|
double accountequity = AccountInfoDouble(ACCOUNT_EQUITY);
|
|
accountprofit = accountequity - accountbalancebeginning;
|
|
accountprofit = NormalizeDouble(accountprofit,2);
|
|
Comment("\nServertime: ", TimeCurrent(),
|
|
"\nCurrenttime: ",TimeCurrent(),
|
|
"\nProfit: ",accountprofit,
|
|
"\nEquity: ",accountequity,
|
|
"\nPinkAMA-Value ",PinkAMACurrentValue,
|
|
"\nYellAMA-Value ",YellAMACurrentValue,
|
|
"\nRedAMA-Value ",RedAMACurrentValue);
|
|
|
|
}//END TIMEFRAME
|
|
}//END ONTICK
|
|
|