PaPP v2: fix SL widening bug, validazioni asimmetriche, CTrade globale, flag persistenti
This commit is contained in:
@@ -136,7 +136,7 @@ void Lbl(string n,string t,int x,int y,int fs,color c,bool b)
|
||||
ObjectSetInteger(0,o,OBJPROP_YDISTANCE,y);
|
||||
ObjectSetInteger(0,o,OBJPROP_CORNER,CORNER_LEFT_UPPER);
|
||||
ObjectSetString(0,o,OBJPROP_TEXT,t);
|
||||
ObjectSetString(0,o,OBJPROP_FONT,b?"Lucida Console Bold":"Lucida Console");
|
||||
ObjectSetString(0,o,OBJPROP_FONT,b?"Consolas":"Consolas");
|
||||
ObjectSetInteger(0,o,OBJPROP_FONTSIZE,fs);
|
||||
ObjectSetInteger(0,o,OBJPROP_COLOR,c);
|
||||
ObjectSetInteger(0,o,OBJPROP_BACK,false);
|
||||
|
||||
@@ -23,6 +23,7 @@ int bars[8];
|
||||
datetime lastBar = 0;
|
||||
bool buyFired = false;
|
||||
bool sellFired = false;
|
||||
CTrade trade;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
int TimeToBars(int d)
|
||||
@@ -46,9 +47,12 @@ int OnInit()
|
||||
hMA[i] = iMA(_Symbol,_Period,bars[i],0,MODE_SMA,PRICE_CLOSE);
|
||||
if(hMA[i]==INVALID_HANDLE) return INIT_FAILED;
|
||||
}
|
||||
if(DebugPrint) Print("=== PaPP Median EA v2.00 INIT ===");
|
||||
if(DebugPrint) Print("=== PaPP Median EA v2.00 INIT ===");
|
||||
Print(" Lot=",LotSize," Trail=",TrailStart,"/",TrailStep," MaxPos=",MaxPosPerSide);
|
||||
for(int i=0;i<8;i++) Print(" MA[",i,"] bars=",bars[i]);
|
||||
buyFired = (CountPos(POSITION_TYPE_BUY) > 0);
|
||||
sellFired = (CountPos(POSITION_TYPE_SELL) > 0);
|
||||
if(DebugPrint) Print(" Flags restored: buyFired=",buyFired," sellFired=",sellFired);
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
@@ -87,7 +91,6 @@ void TrailAll()
|
||||
double point = SymbolInfoDouble(_Symbol,SYMBOL_POINT);
|
||||
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
|
||||
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
|
||||
CTrade trade;
|
||||
for(int i=PositionsTotal()-1; i>=0; i--)
|
||||
{
|
||||
ulong t=PositionGetTicket(i);
|
||||
@@ -122,7 +125,6 @@ void TrailAll()
|
||||
void UpdateTPSL(double median)
|
||||
{
|
||||
double point = SymbolInfoDouble(_Symbol,SYMBOL_POINT);
|
||||
CTrade trade;
|
||||
for(int i=PositionsTotal()-1; i>=0; i--)
|
||||
{
|
||||
ulong t=PositionGetTicket(i);
|
||||
@@ -139,6 +141,8 @@ void UpdateTPSL(double median)
|
||||
double newTP = NormalizeDouble(median,_Digits);
|
||||
double newSL = NormalizeDouble(isBuy ? entry-tpDist : entry+tpDist,_Digits);
|
||||
if(MathAbs(newTP-currTP)<=point && MathAbs(newSL-currSL)<=point) continue;
|
||||
if(isBuy && newSL <= currSL+point) continue;
|
||||
if(!isBuy && newSL >= currSL-point) continue;
|
||||
|
||||
if(DebugPrint) Print(">>> UPDATE t",t," TP=",DoubleToString(newTP,_Digits),
|
||||
" SL=",DoubleToString(newSL,_Digits));
|
||||
@@ -217,10 +221,10 @@ void OnTick()
|
||||
double entry = ask;
|
||||
double tpDist = MathAbs(median-entry);
|
||||
double sl = NormalizeDouble(entry-tpDist,_Digits);
|
||||
double tp = NormalizeDouble(median,_Digits);
|
||||
if(sl>=point)
|
||||
{
|
||||
if(DebugPrint) Print(">>> BUY: bid=",DoubleToString(bid,_Digits),
|
||||
double tp = NormalizeDouble(median,_Digits);
|
||||
if(tpDist>=point)
|
||||
{
|
||||
if(DebugPrint) Print(">>> BUY: bid=",DoubleToString(bid,_Digits),
|
||||
" < buyBand=",DoubleToString(buyBand,_Digits),
|
||||
" TP=",DoubleToString(tp,_Digits)," SL=",DoubleToString(sl,_Digits),
|
||||
" (",DoubleToString(tpDist/point,0),"pts)");
|
||||
|
||||
Reference in New Issue
Block a user