| View previous topic :: View next topic |
| Author |
Message |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Wed Dec 19, 2012 6:07 am Post subject: Returned Wrong RSI Values, why? |
|
|
Hi, all experienced,
I have a simple code to create a RSI indicator for each of 10 symbols, and then get the 'last bar' and 'second bar from last' RSI value of each 10 symbols.
but the Journal keeps reading the returned RSI value as 105 for all 10 pairs regardless of bar index.
Could you shed the light? I attach the code below:
Many Thanks!
| Code: |
// External Vars
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';
// Global Vars
sym: array[1..10] of String;
indiRSI: array[1..10] of integer;
pairRSI_1: array[1..10] of double; //{last closed RSI, index 1}
pairRSI_2: array[1..10] of double; //{the 2nd from last RSI, index 2}
delta_RSI: array[1..10] of double;
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 Get10PairRSI();
var
n: integer;
begin
SetSymbols();
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], 1, 0);// problems here!!!
print('pairRSI_1{'+floattostr(pairRSI_1[n])+'}');
pairRSI_2[n] := GetIndicatorValue(indiRSI[n], 2, 0);// problems here!!!
print('pairRSI_2{'+floattostr(pairRSI_2[n])+'}');
delta_RSI[n] := abs(pairRSI_1[n] - pairRSI_2[n]);
end
end; |
|
|
| Back to top |
|
 |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Wed Dec 19, 2012 3:44 pm Post subject: |
|
|
| by the way, i didn't do 'createindicator' in ResetStrategy. does it matter?
|
|
| Back to top |
|
 |
KelvinHand
Joined: 02 Jan 2011 Posts: 89
|
Posted: Wed Dec 19, 2012 11:17 pm Post subject: |
|
|
| charvo wrote: | | by the way, i didn't do 'createindicator' in ResetStrategy. does it matter? |
It stated clearly in the Strategies API under the Note:
| Code: |
This function should be called only! in the ResetStrategy procedure. After you obtain the indicator handle you should store it in the global variable and use with the GetIndicatorValue function to obtain indicator values. This function will place the indicator to the selected currency and timeframe on the chart. If this indicator already exists it will be used without creating the new one. The strategy will lock this indicator during its execution so you will not be able to remove it from the chart manually. But after disconnect it will be unlocked.
|
|
|
| Back to top |
|
 |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Thu Dec 20, 2012 5:01 am Post subject: |
|
|
Thanks, Kelvin, my bad, I was dumb not to read that part.
I did move it 'createindicator' to 'reset', however, the returned RSI values still are 105, not sure why.
Please check my code, it is simple, it is long only because it reads 10 pairs' RSI values.
| Code: |
library question;
uses
Math,
SysUtils,
DateUtils,
Graphics,
Dialogs,
StrategyInterfaceUnit,
TechnicalFunctions;
//external parameters
var
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';
// global variables
sym: array[1..10] of String;
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;
SysTF: integer;
AvgRSIdelta: double;
procedure InitStrategy; stdcall;
begin
StrategyShortName('RC_RSI');
StrategyDescription('RC that is easy.');
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);
end;
procedure DoneStrategy; stdcall;
begin
end;
procedure ResetStrategy; stdcall;
var
n: integer;
begin
indiRSI[1] := CreateIndicator(Pair1, 60, 'RSI', '14;Close');
indiRSI[2] := CreateIndicator(Pair2, 60, 'RSI', '14;Close');
indiRSI[3] := CreateIndicator(Pair3, 60, 'RSI', '14;Close');
indiRSI[4] := CreateIndicator(Pair4, 60, 'RSI', '14;Close');
indiRSI[5] := CreateIndicator(Pair5, 60, 'RSI', '14;Close');
indiRSI[6] := CreateIndicator(Pair6, 60, 'RSI', '14;Close');
indiRSI[7] := CreateIndicator(Pair7, 60, 'RSI', '14;Close');
indiRSI[8] := CreateIndicator(Pair8, 60, 'RSI', '14;Close');
indiRSI[9] := CreateIndicator(Pair9, 60, 'RSI', '14;Close');
indiRSI[10] := CreateIndicator(Pair10, 60, 'RSI', '14;Close');
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 Get10PairRSI();
var
n: integer;
begin
for n := 1 to 10 do
begin
pairRSI_1[n] := GetIndicatorValue(indiRSI[n], 1, 0);
print('indi. handle {'+inttostr(n)+'} is {'+inttostr(indiRSI[n]));
print('Upon n is {' + inttostr(n) + '}, pairRSI_1{'+floattostr(pairRSI_1[n])+'}');
pairRSI_2[n] := GetIndicatorValue(indiRSI[n], 2, 0);
print('Upon n is {' + inttostr(n) + '}, 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 GetSingleTick; stdcall;
begin
SetSymbols();
if (MinuteOf(TimeCurrent) = 20) or (MinuteOf(TimeCurrent) = 40) then ChangeGear();
Print('**************GetSingleTick Done****************');
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
|
I also attache the screenshot of the journal prints:
| KelvinHand wrote: |
It stated clearly in the Strategies API under the Note:
| Code: |
This function should be called only! in the ResetStrategy procedure.
|
|
| Description: |
|
| Filesize: |
125.71 KB |
| Viewed: |
4052 Time(s) |

|
|
|
| Back to top |
|
 |
Phil_Trade
Joined: 31 Jan 2012 Posts: 74
|
Posted: Thu Dec 20, 2012 8:23 am Post subject: |
|
|
Hi
problem is at
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);
If you ask properties tabs of the strategy, you will only see G for GBPUSD E for EURUSD etc
It's OK if you put it in comment //
I'm using this code to select Pairs
RegOption('Paire Test to Open', ot_EnumType,DeviseTest);
AddOptionValue('Paire Test to Open', 'AUCUNE');
AddOptionValue('Paire Test to Open', 'EURUSD');
AddOptionValue('Paire Test to Open', 'USDJPY');
AddOptionValue('Paire Test to Open', 'GBPUSD');
AddOptionValue('Paire Test to Open', 'USDCHF');
AddOptionValue('Paire Test to Open', 'NZDUSD');
AddOptionValue('Paire Test to Open', 'EURGBP');
AddOptionValue('Paire Test to Open', 'EURJPY');
AddOptionValue('Paire Test to Open', 'AUDUSD');
AddOptionValue('Paire Test to Open', 'GBPCHF');
AddOptionValue('Paire Test to Open', 'GBPJPY');
AddOptionValue('Paire Test to Open', 'USDCAD');
AddOptionValue('Paire Test to Open', 'NZDJPY');
AddOptionValue('Paire Test to Open', 'EURCHF');
AddOptionValue('Paire Test to Open', 'CHFJPY');
AddOptionValue('Paire Test to Open', 'EURCAD');
AddOptionValue('Paire Test to Open', 'AUDJPY');
Philippe
_________________ Philippe |
|
| Back to top |
|
 |
KelvinHand
Joined: 02 Jan 2011 Posts: 89
|
Posted: Thu Dec 20, 2012 8:43 am Post subject: |
|
|
| charvo wrote: | Thanks, Kelvin, my bad, I was dumb not to read that part.
I did move it 'createindicator' to 'reset', however, the returned RSI values still are 105, not sure why.
Please check my code, it is simple, it is long only because it reads 10 pairs' RSI values.
|
Found some error in your code, based on previous strategy written by others in this forum, they all written in the same format:
1. Your Pairs should declare using PChar after the RegOption()
eg.
Pair1: PChar = nil;
2. Your RegOption should use ot_Currency not ot_String:
RegOption('Pair 1', ot_Currency, Pair1);
3. The assignment for PChar as follow:
eg. ReplaceStr(Pair1, 'GBPUSD');
It is possible your pairs is not register properly and thing not working.
Correct these problem first before proceed next
|
|
| Back to top |
|
 |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Thu Dec 20, 2012 3:54 pm Post subject: |
|
|
Thanks a lot, Kelvin and Phil.
I didn't realise it could be the symbols' problem
actually, my strategy works fine except this RSI problem. the strategy trades 10 pairs well. so I didn't think about the symbols/currencies may have something wrong.
The RSI part is only an additional function in my code. The external vars, currency declarations have been all working fine.
I cannot work on it now in office, I'll try what you suggest when back home. Many thanks again!
You guys have a wonderful holiday!
|
|
| Back to top |
|
 |
KelvinHand
Joined: 02 Jan 2011 Posts: 89
|
Posted: Thu Dec 20, 2012 4:08 pm Post subject: |
|
|
| charvo wrote: | Thanks a lot, Kelvin and Phil.
I didn't realise it could be the symbols' problem
actually, my strategy works fine except this RSI problem. the strategy trades 10 pairs well. so I didn't think about the symbols/currencies may have something wrong.
The RSI part is only an additional function in my code. The external vars, currency declarations have been all working fine.
I cannot work on it now in office, I'll try what you suggest when back home. Many thanks again!
You guys have a wonderful holiday! |
OK. I got it work.
| Code: |
2012.02.06 15:20:45 indi. handle {7} is {64217424
2012.02.06 15:20:45 Upon n is {7}, pairRSI_1{43.7081490571674}
2012.02.06 15:20:45 Upon n is {7}, pairRSI_2{33.6822959764042}
|
| Code: |
library RC_RSI;
uses
Math,
SysUtils,
DateUtils,
Graphics,
Dialogs,
StrategyInterfaceUnit,
TechnicalFunctions;
//external parameters
var
Pair1: PChar = nil;
Pair2: PChar = nil;
Pair3: PChar = nil;
Pair4: PChar = nil;
Pair5: PChar = nil;
Pair6: PChar = nil;
Pair7: PChar = nil;
Pair8: PChar = nil;
Pair9: PChar = nil;
Pair10: PChar = nil;
// global variables
sym: array[1..10] of String;
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;
SysTF: integer;
AvgRSIdelta: double;
procedure InitStrategy; stdcall;
begin
StrategyShortName('RC_RSI');
StrategyDescription('RC that is easy.');
ReplaceStr(Pair1, 'GBPUSD');
ReplaceStr(Pair2, 'EURJPY');
ReplaceStr(Pair3, 'AUDUSD');
ReplaceStr(Pair4, 'NZDJPY');
ReplaceStr(Pair5, 'USDCAD');
ReplaceStr(Pair6, 'GBPJPY');
ReplaceStr(Pair7, 'EURUSD');
ReplaceStr(Pair8, 'AUDJPY');
ReplaceStr(Pair9, 'NZDUSD');
ReplaceStr(Pair10, 'USDJPY');
RegOption('Pair 1', ot_Currency, Pair1);
RegOption('Pair 2', ot_Currency, Pair2);
RegOption('Pair 3', ot_Currency, Pair3);
RegOption('Pair 4', ot_Currency, Pair4);
RegOption('Pair 5', ot_Currency, Pair5);
RegOption('Pair 6', ot_Currency, Pair6);
RegOption('Pair 7', ot_Currency, Pair7);
RegOption('Pair 8', ot_Currency, Pair8);
RegOption('Pair 9', ot_Currency, Pair9);
RegOption('Pair 10', ot_Currency, Pair10);
end;
procedure DoneStrategy; stdcall;
begin
end;
procedure ResetStrategy; stdcall;
begin
indiRSI[1] := CreateIndicator(Pair1, 60, 'RSI', '14;Close');
indiRSI[2] := CreateIndicator(Pair2, 60, 'RSI', '14;Close');
indiRSI[3] := CreateIndicator(Pair3, 60, 'RSI', '14;Close');
indiRSI[4] := CreateIndicator(Pair4, 60, 'RSI', '14;Close');
indiRSI[5] := CreateIndicator(Pair5, 60, 'RSI', '14;Close');
indiRSI[6] := CreateIndicator(Pair6, 60, 'RSI', '14;Close');
indiRSI[7] := CreateIndicator(Pair7, 60, 'RSI', '14;Close');
indiRSI[8] := CreateIndicator(Pair8, 60, 'RSI', '14;Close');
indiRSI[9] := CreateIndicator(Pair9, 60, 'RSI', '14;Close');
indiRSI[10]:= CreateIndicator(Pair10, 60, 'RSI', '14;Close');
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 Get10PairRSI();
var
n: integer;
begin
for n := 1 to 10 do
begin
if indiRSI[n] <> 0 then
begin
pairRSI_1[n] := GetIndicatorValue(indiRSI[n], 1, 0);
print('indi. handle {'+inttostr(n)+'} is {'+inttostr(indiRSI[n])+'} for Pair ' + Sym[n]);
print('Upon n is {' + inttostr(n) + '}, pairRSI_1{'+floattostr(pairRSI_1[n])+'}');
pairRSI_2[n] := GetIndicatorValue(indiRSI[n], 2, 0);
print('Upon n is {' + inttostr(n) + '}, pairRSI_2{'+floattostr(pairRSI_2[n])+'} for Pair ' + Sym[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
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 GetSingleTick; stdcall;
begin
SetSymbols();
if (MinuteOf(TimeCurrent) = 20) or (MinuteOf(TimeCurrent) = 40) then ChangeGear();
//Print('**************GetSingleTick Done****************');
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
|
Last edited by KelvinHand on Thu Dec 20, 2012 4:54 pm; edited 4 times in total |
|
| Back to top |
|
 |
Phil_Trade
Joined: 31 Jan 2012 Posts: 74
|
Posted: Thu Dec 20, 2012 4:10 pm Post subject: |
|
|
| charvo wrote: | Thanks a lot, Kelvin and Phil.
I didn't realise it could be the symbols' problem
actually, my strategy works fine except this RSI problem. the strategy trades 10 pairs well. so I didn't think about the symbols/currencies may have something wrong.
The RSI part is only an additional function in my code. The external vars, currency declarations have been all working fine.
I cannot work on it now in office, I'll try what you suggest when back home. Many thanks again!
You guys have a wonderful holiday! |
You're welcome
Don't hesitate to share part of code that's working well !  May be we can improve it together
Philippe
_________________ Philippe |
|
| Back to top |
|
 |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Thu Dec 20, 2012 7:32 pm Post subject: |
|
|
Oh, my heavens, Kelvin, you are incredible!
so looks this is really my 'variable declaration' mistakes, ... i am too dumb...
thousand thanks to you for i can continue on my coding during this holiday.
| KelvinHand wrote: |
OK. I got it work.
|
|
|
| Back to top |
|
 |
charvo
Joined: 04 Dec 2012 Posts: 32
|
Posted: Thu Dec 20, 2012 7:45 pm Post subject: |
|
|
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: |
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 |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|