Robot Example 1 – Random Entries

2

Here is the GFT CTL source code for our first example robot, which uses random entries and fixed take profit and stop loss levels.

//+------------------------------------------------------------------+
//|                                                     GuruEx01.ctl |
//|     Copyright © 2009, Marketing Dreams Ltd. All Rights Reserved. |
//|                                         http://trading-gurus.com |
//|                                                                  |
//| GuruTrader™ example 1                                            |
//| Version 1.0                                                      |
//|                                                                  |
//| About as simple a "robot" as it is possible to produce           |
//| Despite its simplicity it still manages to "predict the future"  |
//| with 100% accuracy....                                           |
//| ....in backtesting EUR/USD on one of my demo accounts            |
//| between January 5th 2009 and April 11th 2009                     |
//|                                                                  |
//| Wealth Warning! This expert is for educational purposes only.    |
//| It should NEVER be used on a live account. Past performance is   |
//| in no way indicative of future results!                          |
//+------------------------------------------------------------------+
strategy GuruEx01;
input ProfitTarget=100, StopLoss=1000, Lots = 1, FixedSpread = 2;
vars CurrBid(number), PrevBid(number), LastIndex(number), FirstIndex(number), Entry(number), Stop(number), Limit(number);
begin
  FirstIndex := front(close);
  LastIndex := back(close);
  if ((LastIndex - FirstIndex) < 1) then     return;          PrevBid := close[LastIndex - 1];   CurrBid := close[LastIndex];   if (positionvolume() = 0) then begin     cancel_all_limits();     cancel_all_stops();     if (CurrBid > PrevBid) then begin
      buy(Lots);
      Entry := CurrBid + FixedSpread * 0.0001;
      Limit := Entry + ProfitTarget * 0.0001;
      Stop := Entry - StopLoss * 0.0001;
      limit_sell(Lots, Limit);
      stop_sell(Lots, Stop);
      print("Long at " + timestamptostr(Timestamp[LastIndex]) + ", Price: " + numbertostring(Entry) + ", Target: " + numbertostring(Limit) + ", Stop: " + numbertostring(Stop));
    end
    else if (CurrBid < PrevBid) then begin
      sell(Lots);
      Entry := CurrBid;
      Limit := Entry - ProfitTarget * 0.0001;
      Stop := Entry + StopLoss * 0.0001;
      limit_buy(Lots, Limit);
      stop_buy(Lots, Stop);
      print("Short at " + timestamptostr(Timestamp[LastIndex]) + ", Price: " + numbertostring(Entry) + ", Target: " + numbertostring(Limit) + ", Stop: " + numbertostring(Stop));
    end;
  end;
end.

Comments on Robot Example 1 – Random Entries Leave a Comment

May 4, 2010

Math @ 4:19 pm #

Hello
it returns some errors when compiling in chartstudio.
Could you fix it?
THANKS

Leave a Comment

Fields marked by an asterisk (*) are required.