Is this possible?

How to create strategies and indicators
Message
Author
Orpexo
Posts: 5
Joined: Sun Nov 10, 2013 2:36 am

Is this possible?

#1 Postby Orpexo » Sun Nov 10, 2013 3:31 am

Hello backtesters,

I have a system which is partially mechanical and partially discretionary. I developed it with manual backtesting only (with ForexTester2). I never used API with FT2.

The mechanical part uses moving averages and CCI on two diferent timeframes to produce a signal. Once I have the mechanical signal, I apply the other part of my strategy which cannot be done with indicators and open an order eventually but not every time. I always set SL and TP by hand.

I know basics of C language and coded multiple EAs for MT4.

I want to update my trading system modifying a few little things, which means lots of backtesting ahead. I would like to code a FT2 strategy to make the mechanical part of my system for me during the backtest. Before throwing myself into learning delphi coding, I would like to make sure it is possible to do something like that:

- I would backtest on 6 pairs at once.
- I want the strategy (or strategies) to look at MAs and CCI on multiple time-frames for each currency.
- When a signal is given, the goal is not to enter the trade directly, but simply to pause the time, maybe pop up a window indicating on which currency and which timeframe the signal happened, and wait for me to decide to make my entry or skip the trade.
- Then I would resume the timespeed and strategies should keep looking for signals.
- Also I would like to be able to pause/resume the time manually when I want for updating my trailing stop by hand.

Please tell me if this is possible.
If you have a code doing something similar that you would share for me to use as an example I would be thankful :)

Orpexo
Posts: 5
Joined: Sun Nov 10, 2013 2:36 am

#2 Postby Orpexo » Sun Nov 10, 2013 11:39 am

So I started playing with delphi 7.

I am trying to have a pop-up window at MA crossings. The pop up either comes up an infinite amount of time, or not at all. I'd like the part of my code checking up for my signalbeing run only once for every M15 candle for example but cannot find how to do that yet.

Also I didn't find anything showing how the tester time could be paused by a strategy :/

Phil_Trade
Posts: 94
Joined: Tue Jan 31, 2012 5:14 am
Contact:

Re: Is this possible?

#3 Postby Phil_Trade » Sun Nov 10, 2013 1:32 pm

Orpexo wrote:Hello backtesters,

I have a system which is partially mechanical and partially discretionary. I developed it with manual backtesting only (with ForexTester2). I never used API with FT2.

The mechanical part uses moving averages and CCI on two diferent timeframes to produce a signal. Once I have the mechanical signal, I apply the other part of my strategy which cannot be done with indicators and open an order eventually but not every time. I always set SL and TP by hand.

I know basics of C language and coded multiple EAs for MT4.

I want to update my trading system modifying a few little things, which means lots of backtesting ahead. I would like to code a FT2 strategy to make the mechanical part of my system for me during the backtest. Before throwing myself into learning delphi coding, I would like to make sure it is possible to do something like that:

- I would backtest on 6 pairs at once.
- I want the strategy (or strategies) to look at MAs and CCI on multiple time-frames for each currency.
- When a signal is given, the goal is not to enter the trade directly, but simply to pause the time, maybe pop up a window indicating on which currency and which timeframe the signal happened, and wait for me to decide to make my entry or skip the trade.
- Then I would resume the timespeed and strategies should keep looking for signals.
- Also I would like to be able to pause/resume the time manually when I want for updating my trailing stop by hand.

Please tell me if this is possible.
If you have a code doing something similar that you would share for me to use as an example I would be thankful :)


Hello Orpexo

Yes, all this can be done

cheers

Philippe
my live account - 8 based pairs with optimized parameters : +188%
http://www.myfxbook.com/members/Philipp ... jpg/519044
TradeSlide : http://bit.ly/14R9Nf6

to be informed about Windev/MT4 services : a04486-tradingsignal@yahoo.fr

Phil_Trade
Posts: 94
Joined: Tue Jan 31, 2012 5:14 am
Contact:

#4 Postby Phil_Trade » Sun Nov 10, 2013 1:39 pm

Orpexo wrote:So I started playing with delphi 7.

I am trying to have a pop-up window at MA crossings. The pop up either comes up an infinite amount of time, or not at all. I'd like the part of my code checking up for my signalbeing run only once for every M15 candle for example but cannot find how to do that yet.

Also I didn't find anything showing how the tester time could be paused by a strategy :/


You will need this 'uses' setting at the beginning of your code

Code: Select all

uses
  DateUtils,
  StrUtils,
  Math,
  SysUtils,
  Dialogs,
  Variants,
  Graphics,
  Windows,
  StrategyInterfaceUnit,
  TechnicalFunctions;



Example of code i'm using :

Code: Select all

Procedure AskUser( Message : AnsiString); stdcall;
begin
if EnOptimisation=1 then exit;
if ShowTradeMessageOnScreen=0 then
begin
if PauseWhenShowTradeMessageOnScreen=0 then pause;
MessageDlg(Message,mtCustom, [mbOk], 0);
if ContinueWhenPressOKforShowTradeMessage=0 then resume

end;
end


example of call :

Code: Select all

if ValeurFermeTMAD1 > ValeurCrossTMAD1 then AskUser('ATTENTION Valeur Filtre Cloture trade Slope TMA D1 > Valeur Filtre Prise Trade Slope TMA D1');


cheers

Philippe
my live account - 8 based pairs with optimized parameters : +188%

http://www.myfxbook.com/members/Philipp ... jpg/519044

TradeSlide : http://bit.ly/14R9Nf6



to be informed about Windev/MT4 services : a04486-tradingsignal@yahoo.fr

Orpexo
Posts: 5
Joined: Sun Nov 10, 2013 2:36 am

#5 Postby Orpexo » Sun Nov 10, 2013 4:25 pm

Hi Philippe,

Thank you very much for your help. From the few tests I made today on delphi I beleive I will be able to do what, even if I'll probably struggle a bit more to code my exact strategy.

From your code it looks like you are french. I am also french :)
Nice myFXbook!

Phil_Trade
Posts: 94
Joined: Tue Jan 31, 2012 5:14 am
Contact:

#6 Postby Phil_Trade » Sun Nov 10, 2013 5:50 pm

Orpexo wrote:Hi Philippe,

Thank you very much for your help. From the few tests I made today on delphi I beleive I will be able to do what, even if I'll probably struggle a bit more to code my exact strategy.

From your code it looks like you are french. I am also french :)
Nice myFXbook!


alors si tu souhaites quelques infos ou aide sur FT, Delphi ou mes services :)

n'hésite pas !

Philippe
my live account - 8 based pairs with optimized parameters : +188%

http://www.myfxbook.com/members/Philipp ... jpg/519044

TradeSlide : http://bit.ly/14R9Nf6



to be informed about Windev/MT4 services : a04486-tradingsignal@yahoo.fr

Orpexo
Posts: 5
Joined: Sun Nov 10, 2013 2:36 am

#7 Postby Orpexo » Mon Nov 11, 2013 6:08 am

Merci ^^

In case somebody needs the same thing I do, I am posting the code I made so far:

This will pop up a window indicating a long or short signal at simple moving average M15 crossover, and pause the test. It can give only one signal every two hours. It also gives an indication for suitable position sizing which should work for the following pairs:
GBPUSD, EURUSD, AUDUSD, USDCAD, USDCHF, EURCHF, EURGBP, USDJPY, EURJPY


//-------------------------------------------------------------------------
// Trying to code Bounce
//-------------------------------------------------------------------------
library testbounce;


uses
DateUtils,
StrUtils,
Math,
SysUtils,
Dialogs,
Variants,
Graphics,
Windows,
StrategyInterfaceUnit,
TechnicalFunctions;

var
// External parameters
Currency: PChar = nil;
TimeFrame: integer;
period1: integer;
period2: integer;
risk: Double;

// custom variables
IndSMAfastM15: integer;
IndSMAslowM15: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
OrderHandle: integer;
signalTime: TDateTime;
messageString: string;






{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
StrategyShortName('testBounce');
StrategyDescription('alert on trade opportunities');

// Register external parameters
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');


RegOption('SMAfast period', ot_Integer, period1);
SetOptionRange('SMAfast period', 2, MaxInt);
period1 := 6;

RegOption('SMAslow period', ot_Integer, period2);
SetOptionRange('SMAslow period', 2, MaxInt);
period2 := 12;

RegOption('risk%', ot_Double, risk);
SetOptionDigits('risk%', 2);
risk := 2.00;

end;

{-----Done strategy---------------------------------------------------------}
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency);
end;

{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;
begin
//Create Indicator
IndSMAslowM15 := CreateIndicator(Currency, PERIOD_M15, 'MovingAverage', format('%d;%d;%d;%s;Close', [period2,0,0,StrMAType(ma_SMA)]));
IndSMAfastM15 := CreateIndicator(Currency, PERIOD_M15, 'MovingAverage', format('%d;%d;%d;%s;Close', [period1,0,0,StrMAType(ma_SMA)]));
signalTime := iTime(Symbol, PERIOD_M15, 0);
OrderHandle := -1;
end;


Procedure AskUser( Message : AnsiString); stdcall;
begin
pause;
MessageDlg(Message,mtCustom, [mbOk], 0);
end;



{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
var

SMAfast_M15, SMAslow_M15: double;
previousSMAfast_M15, previousSMAslow_M15: double;
lot_size, refPrice: double;



begin

// running strategy only once per M15 candle
if (iTime(Symbol, PERIOD_M15, 0) < signalTime) then exit;

// indicators
SMAfast_M15 := GetIndicatorValue(IndSMAfastM15, 0, 0);
SMAslow_M15 := GetIndicatorValue(IndSMAslowM15, 0, 0);
previousSMAfast_M15 := GetIndicatorValue(IndSMAfastM15, 1, 0);
previousSMAslow_M15 := GetIndicatorValue(IndSMAslowM15, 1, 0);


//reading price of reference pair for position sizing
if ( Symbol ='GBPUSD') or ( Symbol='EURUSD') or (Symbol='AUDUSD') then refPrice:=1;
if ( Symbol ='USDCAD') then refPrice:=MarketInfo('USDCAD',MODE_BID);
if ( Symbol = 'USDCHF' ) or ( Symbol = 'EURCHF' ) then refPrice:=MarketInfo('USDCHF',MODE_BID);
if ( Symbol = 'EURGBP' ) then refPrice:=1/MarketInfo('GBPUSD',MODE_BID);
if ( Symbol = 'USDJPY' ) or ( Symbol = 'EURJPY' ) then refPrice:=0.01*MarketInfo('USDJPY',MODE_BID);


// short Signal
if (SMAfast_M15<SMAslow_M15) and (previousSMAfast_M15>previousSMAslow_M15) then
begin
lot_size:= AccountBalance()*refPrice*risk*0.001;
messageString:= 'SHORT signal on '+Symbol+'!'+#13#10+'Lots = '+FloatToStrF(lot_size,ffGeneral,20,4)+' / SLpips';
AskUser(messageString);
signalTime:=iTime(Symbol, PERIOD_M15, 0);
signalTime:= IncMinute(signalTime, 120);
end;



// long Signal
if (SMAfast_M15 > SMAslow_M15) and (previousSMAfast_M15 < previousSMAslow_M15) then
begin
lot_size:= AccountBalance()*refPrice*risk*0.001;
messageString:= 'LONG signal on '+Symbol+'!'+#13#10+'Lots = '+FloatToStrF(lot_size,ffGeneral,20,4)+' / SLpips';
AskUser(messageString);
signalTime:=iTime(Symbol, PERIOD_M15, 0);
signalTime:= IncMinute(signalTime, 120);
end;


end;





exports

InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;

end.



edit:
you probably want to add the following to this code to avoid getting mixed signals from a pair to another:
// check our currency
if Symbol <> string(Currency) then exit;

// set currency and timeframe
SetCurrencyAndTimeframe(string(Currency), PERIOD_M15);

Orpexo
Posts: 5
Joined: Sun Nov 10, 2013 2:36 am

#8 Postby Orpexo » Fri Nov 15, 2013 1:27 pm

I was able to code my strategy and delay messages from signals appearing at night to the morning.

Is it possible to take screenshots with an API strategy?
edit: I found this thread:
http://forextester.com/forum/viewtopic. ... creen+shot
Is this still the best thing to do?


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 24 guests