not a problem, Phil.
i didn't post the code as I thought it is too long, and you helpers won't bother to read
i thought it might be of value to those who come to learn delphi coding in future, as my code seems okay to run (though not logically exactly as it should function)
I also have not updated/compiled based on Kelvin's updates as I cannot now in office.
the code is below. it is running, but it is a little messy since I've not finished all work yet. If you run it in FT2, it trades and exits okay since I forced [SysTF := 60; ] in 'GetSingleTick', when I had this RSI problem. you can try to to play with it. the strategy's idea is very interesting. you may observe it.
The strategy is simple:
1. pick the biggest winner (in terms of % price change) among 10 popular pairs
2. keep adding position of this pair by an interval of time (***)
3. the interval of time may be 30M, H1, H4 or D1 which is determined by whether or not the RSI is active enough.
4. all the positions will be exit when the takeprofit or stoploss is reached.
***. this pair, during the trading period, may of course switch among 10 currencies, but the EA will always pick the "biggest winner" pair to trade.
as to the RSI values, the EA will add positions every 30 minutes, if the Average RSI is high; ....... the lower RSI value, the longer timeframe. and the attached code cannot fulfil the NO.3 above. the strategy can only trade based on H1 intervals.
Code: Select all
library RC_Prototype3;
uses
Math,
SysUtils,
DateUtils,
Graphics,
Dialogs,
StrategyInterfaceUnit,
TechnicalFunctions;
//external parameters
var
SpecificLot: double = 0.02;
ExitLot: double = 0.01;
FreeRunners: integer= 2;
ProfitPct: double = 1.0;
FailurePct: double = 1.0;
DollarProfitTarget: double = 70;
DollarLossFail: double = -400;
MagicNumber: integer= 912;
RunFreeLot: boolean= true;
Pair1: String = 'GBPUSD';
Pair2: String = 'EURJPY';
Pair3: String = 'AUDUSD';
Pair4: String = 'NZDJPY';
Pair5: String = 'USDCAD';
Pair6: String = 'GBPJPY';
Pair7: String = 'EURUSD';
Pair8: String = 'AUDJPY';
Pair9: String = 'NZDUSD';
Pair10: String = 'USDJPY';
TAindi: integer = 0;
StartHour: integer= 4;
FinishHour: integer= 21;
slippage: integer= 30;
// global variables
sym: array[1..10] of String;
initAskBid: array[1..10] of Double;
PhantomPL: array[1..10] of Double;
PairPL: array[1..10] of Double;
PairBuys: array[1..10] of integer;
PairSells: array[1..10] of integer;
prevBid: array[1..10] of double;
prevAsk: array[1..10] of double;
pairPoint: array[1..10] of double;
pairTickVal:array[1..10] of double;
indiRSI: array[1..10] of integer;
pairRSI_1: array[1..10] of double; {last closed RSI}
pairRSI_2: array[1..10] of double; {the RSI prior to last closed one -- i=2}
delta_RSI: array[1..10] of double;
SymbolMarks:array[1..10] of boolean;
tempcnt1, tempcnt2, i, OrderHandle, SysTF, CutInterval: integer;
NOofSells, NOofBuys, TotalTrades: integer;
RealPhantomWinnerType, Real2ndPhantomWinnerType, BigPhantomWinnerType, BigPhantomLoserType, BiggestWinnerType, BiggestLoserType: TTradePositionType;
RealPhantomWinnerTicket, Real2ndPhantomWinnerTicket, BigPhantomWinnerTicket, BigPhantomLoserTicket, BiggestWinnerTicket, BiggestLoserTicket: integer;
RealPhantomWinnerPL, Real2ndPhantomWinnerPL, BigPhantomWinnerPL, BigPhantomLoserPL, BiggestWinnerPL, BiggestLoserPL: double;
Avg10PairsRSI, AvgRSIdelta: double;
RealPhantomWinnerSymbol, Real2ndPhantomWinnerSymbol, BigPhantomWinnerSymbol, BigPhantomLoserSymbol, BiggestWinnerSymbol, BiggestLoserSymbol: String;
ObjHUDline1, ObjHUDline2, ObjTradingState, ObjEAstatus, ObjDancingPr, EAstatus, TradingStatus, DancingPairs: string;
infonote1, infonote2, infonote3, infonote4, infonote5, infonote6: string;
RealisedLoss, EAfloatPL, EAfProfitPeak, EAfLossPeak: double;
CloseAll, BidsHaveChanged, SymbolMarksCleared, ToAdd, ToCutALoser, SendInstantOrderResult, PhantomsReset, NewBarFormed: boolean;
pairinfo: PCurrencyInfo;
procedure InitStrategy; stdcall;
begin
StrategyShortName('RC_prototype3');
StrategyDescription('RC that is easy.');
RegOption('Specific Lot', ot_Double, SpecificLot);
RegOption('Exit Lot', ot_Double, ExitLot);
RegOption('Free Runners', ot_Integer, FreeRunners);
RegOption('Profit%', ot_Double, ProfitPct);
RegOption('Failure%', ot_Double, FailurePct);
RegOption('Profit$Target', ot_Double, DollarProfitTarget);
RegOption('Loss$Exit', ot_Double, DollarLossFail);
RegOption('Magic Number', ot_Integer, MagicNumber);
RegOption('Pair 1', ot_String, Pair1);
RegOption('Pair 2', ot_String, Pair2);
RegOption('Pair 3', ot_String, Pair3);
RegOption('Pair 4', ot_String, Pair4);
RegOption('Pair 5', ot_String, Pair5);
RegOption('Pair 6', ot_String, Pair6);
RegOption('Pair 7', ot_String, Pair7);
RegOption('Pair 8', ot_String, Pair8);
RegOption('Pair 9', ot_String, Pair9);
RegOption('Pair 10', ot_String, Pair10);
RegOption('TAindi', ot_EnumType, TAindi);
AddOptionValue('TAindi', 'Candle');
AddOptionValue('TAindi', 'RSI');
AddOptionValue('TAindi', 'Momentum');
TAindi := 0;
end;
procedure DoneStrategy; stdcall;
begin
end;
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1;
end;
// *************** start() and its all routines **************
function NewBar(timeframe:integer): boolean; // !! Unfinished
var
found: boolean;
begin
found := true;
NewBar := found;
end;
function SetPoint(aSymbol: string): double;
var
apoint, adigits: double;
begin
if GetCurrencyInfo(aSymbol,pairinfo) then
adigits := pairinfo.Digits;
if adigits < 4 then
apoint := 0.01
else
apoint := 0.001;
Result := apoint;
end;
function SetTickValue(aSymbol: String; aPoint: double): double;
var
aTickval: double;
begin
SetTickValue:= 1;
end;
procedure SetPointsAndTickvalues();
var
n: integer;
begin
for n := 1 to 10 do
begin
pairPoint[n] := SetPoint(sym[n]);
pairTickVal[n] := SetTickValue(sym[n], pairPoint[n]);
end
end;
function CheckPrevPrices(): boolean;
var
n: integer;
begin
for n := 1 to 5 do
begin
if (prevAsk[n] <> 0) and (prevAsk[n] <> MarketInfo(sym[n], MODE_ASK)) then Result := true;
if (prevBid[i] <> 0) and (prevBid[i] <> MarketInfo(sym[n+5], MODE_BID)) then Result := true;
end
end;
procedure UpdatePrevPrices();
var
n: integer;
begin
for n := 1 to 5 do
begin
prevAsk[n] := MarketInfo(sym[n], MODE_ASK);
prevBid[i] := MarketInfo(sym[n+5], MODE_BID);
end
end;
procedure Count_Trades_PL();
var
n: integer;
begin
NOofSells := 0;
NOofBuys := 0;
TotalTrades := 0;
EAfloatPL := 0;
BiggestWinnerPL := 0;
BiggestWinnerTicket := 0;
BiggestWinnerType := tp_Credit;
BiggestWinnerSymbol := '';
BiggestLoserPL := 0;
BiggestLoserTicket := 0;
BiggestLoserType := tp_Credit;
BiggestLoserSymbol := '';
for n := 0 to OrdersTotal - 1 do
begin
OrderSelect(n, Select_By_Pos, mode_trades);
if (OrderMagicNumber = MagicNumber) and (OrderLots = SpecificLot) then
begin
EAfloatPL := EAfloatPL + OrderProfit;
TotalTrades := TotalTrades + 1;
if OrderProfit > BiggestWinnerPL then
begin
BiggestWinnerPL := OrderProfit;
BiggestWinnerTicket := OrderTicket;
BiggestWinnerType := OrderType;
BiggestWinnerSymbol := OrderSymbol;
end;
if OrderProfit < BiggestLoserPL then
begin
BiggestLoserPL := OrderProfit;
BiggestLoserTicket := OrderTicket;
BiggestLoserType := OrderType;
BiggestLoserSymbol := OrderSymbol;
end;
end
end
end;
procedure CloseAllTradesIfNeeded();
var
n, runners: integer;
BEbig, BE2more, freedBig, freed2more, closedbyticket, closedbyhandle: boolean;
begin
if BidsHaveChanged and CloseAll then
begin
print('CATN; totaltrades:{' + IntToStr(totaltrades) + '}, OrdersTotal:{' + inttostr(OrdersTotal));
for n := 0 to OrdersTotal do
begin
//print('Enumerate all <n>: current |n| is {' + inttostr(n));
if OrderSelect(n,SELECT_BY_POS,MODE_TRADES) then
begin
print('Selected <n>: current <n> is {' + inttostr(n));
if (OrderMagicNumber() = MagicNumber) and (OrderLots = SpecificLot) then
begin
print('To handle |n| is {' + inttostr(n));
//print('OrderHandle is {' + inttostr(OrderHandle));
//print('OrderTicket is {' + inttostr(OrderTicket));
if OrderHandle <> -1 then // ??? is this 'OrderHandle' used correctly ???
begin
closedbyticket := CloseOrder(OrderTicket);
if (not closedbyticket) then
begin
print('CloseOrder by ticket fails!');
closedbyhandle := CloseOrder(OrderHandle);
if (not closedbyhandle) then print('CloseOrder by handle fails TOO!')
else print('BUT CloseOrder by handle succeed!');
end;
end;
end;
end;
end
end
end;
procedure SetSymbols();
begin
sym[1] := Pair1;
sym[2] := Pair2;
sym[3] := Pair3;
sym[4] := Pair4;
sym[5] := Pair5;
sym[6] := Pair6;
sym[7] := Pair7;
sym[8] := Pair8;
sym[9] := Pair9;
sym[10] := Pair10;
end;
procedure OpenPhantomTrades();
var
i: integer;
begin
for i:= 1 to 5 do
if initAskBid[i] = 0.0 then
begin
initAskBid[i] := MarketInfo(sym[i], MODE_ASK);
end;
for i:= 6 to 10 do
if initAskBid[i] = 0.0 then
initAskBid[i] := MarketInfo(sym[i], MODE_BID);
// for i:= 1 to 10 do
// if initAskBid[i] = 0.0 then
// Print('failed to get pair{' + sym[i] + '} with ask {' + FloatToStr(MarketInfo(sym[i], MODE_ASK)) + '},bid{' + FloatToStr(MarketInfo(sym[i], MODE_BID)) + '}');
end;
procedure CalcPhantomPL();
var
n: integer;
begin
//SetPointsAndTickvalues();
BigPhantomWinnerPL := 0.0;
BigPhantomWinnerType := tp_Credit;
BigPhantomWinnerSymbol := '';
BigPhantomLoserPL := 0.0;
BigPhantomLoserType := tp_Credit;
BigPhantomLoserSymbol := '';
for n := 1 to 10 do
begin
if initAskBid[n] <> 0 then
begin
if n <=5 then
PhantomPL[n] := 10000 * (MarketInfo(sym[n], mode_bid) - initAskBid[n])/initAskBid[n]
else
PhantomPL[n] := 10000 * (initAskBid[n] - MarketInfo(sym[n], mode_ask))/initAskBid[n]; //PhantomPL[n] := 0.1 * PhantomPL[n] * TickvalArray[n];
if PhantomPL[n] > BigPhantomWinnerPL then
begin
BigPhantomWinnerPL := PhantomPL[n];
BigPhantomWinnerSymbol := sym[n];
if n <= 5 then
BigPhantomWinnerType := tp_Buy
else
BigPhantomWinnerType := tp_Sell;
end;
if PhantomPL[n] < BigPhantomLoserPL then
begin
BigPhantomLoserPL := PhantomPL[n];
BigPhantomLoserSymbol := sym[n];
if n <= 5 then
BigPhantomLoserType := tp_Buy // 1 means long
else
BigPhantomLoserType := tp_Sell; // 0 means short
end
end
else
Print('NIMA initAskBid NO {' + IntToStr(n) + '} is ZERO!');
end;
if BigPhantomWinnerPL > Abs(BigPhantomLoserPL) then
begin
RealPhantomWinnerPL := BigPhantomWinnerPL;
RealPhantomWinnerSymbol := BigPhantomWinnerSymbol;
RealPhantomWinnerType := BigPhantomWinnerType;
end
else
begin
RealPhantomWinnerPL := Abs(BigPhantomLoserPL);
RealPhantomWinnerSymbol := BigPhantomLoserSymbol;
if BigPhantomLoserType = tp_Buy then
RealPhantomWinnerType := tp_Sell;
if BigPhantomLoserType = tp_Sell then
RealPhantomWinnerType := tp_Buy;
end;
//Print('In CalcPhantomPL, BigPhantomWinnerSymbol: {' + BigPhantomWinnerSymbol + '} its PL:{' + FloatToStr(BigPhantomWinnerPL) + '} its posType:{' + IntToStr(integer(BigPhantomWinnerType)));
//Print('In CalcPhantomPL, BigPhantomLoserSymbol: {' + BigPhantomLoserSymbol + '} its PL:{' + FloatToStr(BigPhantomLoserPL) + '} its posType:{' + IntToStr(integer(BigPhantomLoserType)));
//Print('In CalcPhantomPL, RealPhantomWinnerSymbol: {' + RealPhantomWinnerSymbol + '} its PL:{' + FloatToStr(RealPhantomWinnerPL) + '} its posType:{' + IntToStr(integer(RealPhantomWinnerType)));
// later to add: LocateReal2ndPhantomWinner(RealPhantomWinnerSymbol);
end;
procedure ResetPhantoms();
var
n:integer;
begin
for n := 1 to 10 do
begin
initAskBid[n] := 0;
//OrderHandle := -1;
end;
end;
procedure ClearSymbolMarks();
var
n:integer;
begin
for n := 1 to 10 do
begin
SymbolMarks[n] := false;
end;
end;
function SymbolMarked(pairsym:string): boolean;
var
n:integer;
checker: boolean;
begin
checker := false;
for n := 1 to 10 do
if (sym[n] = pairsym) and (SymbolMarks[n] = true) then
begin
checker := true;
Break;
end;
Result := checker;
end;
procedure MarkSymbol(pairsym:string);
var
n:integer;
begin
for n := 1 to 10 do
if sym[n] = pairsym then
begin
SymbolMarks[n] := true;
Break;
end;
end;
procedure AddIfNeeded();
var
n: integer;
pairsym: String;
begin
if (MinuteOf(TimeCurrent) <> 5) and (MinuteOf(TimeCurrent) <> 35) then ClearSymbolMarks();
if BidsHaveChanged and CloseAll = false then
begin
ToAdd := false;
if (SysTF = 60) and (MinuteOf(TimeCurrent) = 5) then ToAdd := true;
if (SysTF = 30) and ( (MinuteOf(TimeCurrent) = 5) or (MinuteOf(TimeCurrent) = 35) ) then ToAdd := true;
if (SysTF = 120) and ((HourOf(Time(0)) mod 2) = 0) and (MinuteOf(TimeCurrent) = 5) then ToAdd := true;
if (SysTF = 240) and ((HourOf(Time(0)) mod 4) = 0) and (MinuteOf(TimeCurrent) = 5) then ToAdd := true;
if ToAdd and (not SymbolMarked(RealPhantomWinnerSymbol)) then
begin
for n := 1 to 10 do
begin
pairsym := sym[n];
if pairsym = RealPhantomWinnerSymbol then
begin
if RealPhantomWinnerType = tp_Buy then
SendInstantOrderResult := SendInstantOrder(sym[n],OP_BUY,SpecificLot,0, 0, 'NIMA',MagicNumber,OrderHandle);
if RealPhantomWinnerType = tp_Sell then
SendInstantOrderResult := SendInstantOrder(sym[n],OP_SELL,SpecificLot,0, 0, 'NIMA',MagicNumber,OrderHandle);
if SendInstantOrderResult then
begin
MarkSymbol(RealPhantomWinnerSymbol);
Print('AddIfN DID place a REAL pos {' + Sym[n] + '.');
end
else
Print('AddIfN FAILED to enter a REAL pos {' + Sym[n] + '.');
end;
end;
end;
end;
end;
function TAValidated(pairsym:string; pairdir:TTradePositionType): boolean;
begin
if TAindi = 0 then
begin
if (pairdir = tp_Buy) and (iOpen(pairsym, SysTF, 1) < iClose(pairsym, SysTF, 1)) then
Result := true;
if (pairdir = tp_Buy) and (iOpen(pairsym, SysTF, 1) > iClose(pairsym, SysTF, 1)) then
Result := false;
if (pairdir = tp_Sell) and (iOpen(pairsym, SysTF, 1) > iClose(pairsym, SysTF, 1)) then
Result := true;
if (pairdir = tp_Sell) and (iOpen(pairsym, SysTF, 1) < iClose(pairsym, SysTF, 1)) then
Result := false;
end;
{if TAindi = 1 then
begin
IndMACD := CreateIndicator(pairsym, SysTF, 'RSI', '14;Close');
if (pairdir = tp_Buy) and (iOpen(pairsym, SysTF, 1) < iClose(pairsym, SysTF, 1)) then
Result := true;
if (pairdir = tp_Buy) and (iOpen(pairsym, SysTF, 1) > iClose(pairsym, SysTF, 1)) then
Result := false;
if (pairdir = tp_Sell) and (iOpen(pairsym, SysTF, 1) > iClose(pairsym, SysTF, 1)) then
Result := true;
if (pairdir = tp_Sell) and (iOpen(pairsym, SysTF, 1) < iClose(pairsym, SysTF, 1)) then
Result := false;
end}
end;
function CutLosers(): boolean;
var
LoserCut: boolean;
begin
if (BiggestLoserTicket > 0) then
begin
Print('!TO cut a PATHETIC' + BiggestLoserSymbol + ' of ticket {' + IntToStr(BiggestLoserTicket) + '} @' + TimeToStr(TimeCurrent));
if OrderSelect(BiggestLoserTicket , SELECT_BY_TICKET, MODE_TRADES) then
begin
if (OrderMagicNumber = MagicNumber) and (OrderLots = SpecificLot) then
begin
LoserCut := CloseOrder(OrderTicket);
if LoserCut then
begin
Print('!A loser: ticket {' + IntToStr(OrderTicket) + '} of ' + OrderSymbol() + IntToStr(integer(OrderType)) + ' is CUT.' );
RealisedLoss := RealisedLoss + BiggestLoserPL;
end;
if (Not LoserCut) then Print('FAILED to cut a loser:ticket {' + IntToStr(OrderTicket) + '} of ' + OrderSymbol() + IntToStr(integer(OrderType)) );
end;
end;
end;
Result := LoserCut;
end;
procedure Get10PairRSI();
var
n: integer;
begin
for n := 1 to 10 do
begin
indiRSI[n] := CreateIndicator(sym[n], SysTF, 'RSI', '14;Close');
print('indi. Handles: {'+inttostr(indiRSI[n])+'} for pair{' + sym[n]+'} of {'+inttostr(n)+'}');
pairRSI_1[n] := GetIndicatorValue(indiRSI[n], 0, 0);
print('pairRSI_1{'+floattostr(pairRSI_1[n])+'}');
pairRSI_2[n] := GetIndicatorValue(indiRSI[n], 1, 0);
print('pairRSI_2{'+floattostr(pairRSI_2[n])+'}');
delta_RSI[n] := abs(pairRSI_1[n] - pairRSI_2[n]);
// if (delta_RSI[n] = 0) then print('deltaRSI{'+inttostr(n)+'} is ZERO, but might be right...');
end
end;
procedure ChangeGear();
begin
Get10PairRSI();
AvgRSIdelta := Mean(delta_RSI);
if (AvgRSIdelta = 0) then print('vvvvvv AvgRSIdelta{'+floattostr(AvgRSIdelta)+'} might be problematic...')
else print('^^^^^^ NOTE THAT AvgRSIdelta is {'+floattostr(AvgRSIdelta)+'}.');
if (AvgRSIdelta < 1) and (SysTF <> 1440) then
begin
SysTF := 1440;
Print('Nima changed to GEAR D1!');
end;
if (AvgRSIdelta >= 1) and (AvgRSIdelta < 2) and (SysTF <> 240) then
begin
SysTF := 240;
Print('Nima changed to GEAR H4!');
end;
if (AvgRSIdelta >= 2) and (AvgRSIdelta < 4) and (SysTF <> 120) then
begin
SysTF := 120;
Print('Nima changed to GEAR H2!');
end;
if (AvgRSIdelta >= 4) and (AvgRSIdelta < 8) and (SysTF <> 60) then
begin
SysTF := 60;
Print('Nima changed to GEAR H1!');
end;
if (AvgRSIdelta >= 8) and (SysTF <> 30) then
begin
SysTF := 30;
Print('Nima changed to GEAR M30!');
end;
end;
procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
begin
SetCurrencyAndTimeframe(sym[1], 60);
ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, 0, 0);
ObjectSetText(ObjHUDline1, note, 9, 'Arial', colorcode);
ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord);
ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord);
end;
procedure HUDprojector2(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
begin
SetCurrencyAndTimeframe(sym[2], 60);
ObjectCreate(ObjHUDline2, OBJ_TEXT, 0, 0, 0);
ObjectSetText(ObjHUDline2, note, 9, 'Arial', colorcode);
ObjectSet(ObjHUDline2, OBJPROP_TIME2, timecoord);
ObjectSet(ObjHUDline2, OBJPROP_PRICE2,pricecoord);
end;
procedure SetHUDtexts();
begin
EAstatus := 'EA is running @' + TimeToStr(Time(0));
TradingStatus := 'EA manages ' + IntToStr(TotalTrades) + ' positions.';
DancingPairs := 'The Real Winner Pair is {' + RealPhantomWinnerSymbol + '} of ' + IntToStr(integer(RealPhantomWinnerType)) + ' type' +'; The Biggest Loser Trade {' + BiggestLoserSymbol + '}';
// check this thread on FT.com for these FT 'types' conversion: <<Please explain the TTypes used..>>
end;
procedure HUD();
begin
SetCurrencyAndTimeframe(sym[10], 60);
{ ObjectCreate(ObjTradingState, OBJ_TEXT, 0, 0, 0);
ObjectSet(ObjTradingState, OBJPROP_SCREENCOORDS,1);
ObjectSetText(ObjTradingState, TradingStatus, 10, 'Arial', clYellow);
ObjectSet(ObjTradingState, OBJPROP_TIME1,50);
ObjectSet(ObjTradingState, OBJPROP_PRICE1,50);
ObjectSet(ObjTradingState, OBJPROP_SCRVALIGNMENT, 1);
ObjectSet(ObjTradingState, OBJPROP_SCRHALIGNMENT, 1);
ObjectCreate(ObjEAstatus, OBJ_TEXT, 0, 0, 0);
ObjectSet(ObjEAstatus, OBJPROP_SCREENCOORDS,2);
ObjectSetText(ObjEAstatus, EAstatus, 10, 'Arial', clRed);
ObjectSet(ObjEAstatus, OBJPROP_TIME1,50);
ObjectSet(ObjEAstatus, OBJPROP_PRICE1,50);
ObjectSet(ObjEAstatus, OBJPROP_VALIGNMENT, tlBottom);
ObjectSet(ObjEAstatus, OBJPROP_HALIGNMENT, taLeftJustify);
ObjectSet(ObjEAstatus, OBJPROP_SCRVALIGNMENT, 2);
ObjectSet(ObjEAstatus, OBJPROP_SCRHALIGNMENT, 2);
}
ObjectCreate(ObjDancingPr, OBJ_TEXT, 0, 0, 0);
ObjectSetText(ObjDancingPr, DancingPairs, 10, 'Arial', clWhite);
ObjectSet(ObjDancingPr, OBJPROP_TIME1, 1200);
ObjectSet(ObjDancingPr, OBJPROP_PRICE1,90);
{ ObjectSet(ObjDancingPr, OBJPROP_VALIGNMENT, 2);
ObjectSet(ObjDancingPr, OBJPROP_HALIGNMENT, 2);
ObjectSet(ObjDancingPr, OBJPROP_VALIGNMENT, tlBottom);
ObjectSet(ObjDancingPr, OBJPROP_HALIGNMENT, taLeftJustify);
ObjectSet(ObjDancingPr, OBJPROP_SCRVALIGNMENT, 3);
ObjectSet(ObjDancingPr, OBJPROP_SCRHALIGNMENT, 3);}
end;
procedure GetSingleTick; stdcall;
// 888888 start 888888
begin
infonote1 := 'EAPL is {' + floatToStr(EAfloatPL) + '}, with target {' + floatToStr(DollarProfitTarget) + '} & Exit {' + floatToStr(DollarLossFail) +'}';
HUDprojector1(infonote1, clGreen, 1000, 90);
infonote2 := 'EA is running @' + TimeToStr(TimeCurrent) + ', CloseAll is {' + BoolToStr(CloseAll, true);
HUDprojector2(infonote2, clRed, 1000, 70);
infonote3 := 'The Real Winner Pair is {' + RealPhantomWinnerSymbol + '} of ' + IntToStr(integer(RealPhantomWinnerType)) + ' type' +'; The Biggest Loser Trade {' + BiggestLoserSymbol + '}';
HUDprojector2(infonote3, clRed, 1000, 50);
SetSymbols();
BidsHaveChanged := CheckPrevPrices();
//Print('BidsHaveChanged = ' + BoolToStr(BidsHaveChanged, True));
//Print('CloseAll = ' + BoolToStr(CloseAll, True));
Count_Trades_PL();
//Print('EAfloatPL is {' + floattostr(EAfloatPL));
if (not CloseAll) and ( ( EAfloatPL > (DollarProfitTarget + Abs(RealisedLoss)) ) or ( (EAfloatPL+RealisedLoss) < DollarLossFail ) ) then
begin
CloseAll := true;
ResetPhantoms();
Print('ResetPhantom is done @ CloseAll');
// putting this subroutine here make sure it runs only once.
end;
if TotalTrades > 0 then
begin
CloseAllTradesIfNeeded();
end;
OpenPhantomTrades();
CalcPhantomPL();
if (MinuteOf(TimeCurrent) = 20) or (MinuteOf(TimeCurrent) = 40) then ChangeGear();
SysTF := 60; // only for test/debug!
//Print('@@@System TF is {' + IntTostr(SysTF) + '}');
SetHUDtexts();
HUD();
//Print('Key Pairs: ' + DancingPairs);
if TotalTrades = 0 then
begin
CloseAll := false;
EAfProfitPeak := 0;
EAfLossPeak := 0;
RealisedLoss := 0;
if (HourOf(Time(0)) < StartHour) or (HourOf(Time(0)) > FinishHour) then
PhantomsReset := true
else
begin
if PhantomsReset = true then
begin
ResetPhantoms();
PhantomsReset := false;
Print('ResetPhantom is done @ Sessions');
end;
end
end;
if TAValidated(RealPhantomWinnerSymbol, RealPhantomWinnerType) then
begin
AddIfNeeded();
//Print('TAV gave a GO!');
end
else //Print('TAV said NO-GO!');
UpdatePrevPrices();
if TotalTrades > 5 then
begin
if TotalTrades <= 9 then CutInterval := 22;
if (TotalTrades > 9) and (TotalTrades <= 15) then CutInterval := 16;
if (TotalTrades > 15) and (TotalTrades <= 22) then CutInterval := 11;
if TotalTrades > 22 then CutInterval := 7;
end;
if ( ToCutALoser and (MinuteOf(TimeCurrent) = 55) and (( HourOf(TimeCurrent) mod CutInterval ) = 0) ) then
begin
if CutLosers() then ToCutALoser := false
else ToCutALoser := true;
end;
if (not ToCutALoser) and BidsHaveChanged and (MinuteOf(TimeCurrent) <> 55) then ToCutALoser := true;
Print('**************GetSingleTick Done****************');
end;
// 888888 start 888888
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
Phil_Trade wrote:Don't hesitate to share part of code that's working well !
:) May be we can improve it together
Philippe