Profile Picture

RE My PaperBroker Question

Posted By jamesluong 7 Years Ago
Message
Posted Saturday February 06 2010
I've been modifying the MyPaperBroker sample posted on the boards by the admins to create my own paperbroker.

A few of the overriding methods (SimBar, SimHighLow and SimOpen) don't seem to be in use in RE 2 v14. However, since these methods aren't in use, the three dictionaries for _high, _low and _open aren't being filled because the private methods aren't being called.

What's the purpose of these dictionaries in this paperbroker?

I want to to calculate slippage based on some percentage between the high / low and open depending on the nature of the trade. Is there an advantage to storing the values in the list instead of keeping the last value in a class variable?


      public override string id()
      {
         return "{A845D94F-B0E0-4368-8507-62B7DB282F6A}";
      }

      Dictionary _highs = new Dictionary();
      Dictionary _lows = new Dictionary();
      Dictionary _opens = new Dictionary();

      private void SetHighLows(NewBarInfo info)
      {
         _highs.Clear();
         _lows.Clear();
         foreach (var kvp in info.bars)
         {
            _highs[kvp.Key] = kvp.Value.High;
            _lows[kvp.Key] = kvp.Value.Low;
         }
      }

      private void SetOpens(NewBarInfo info)
      {
         _opens.Clear();
         foreach (var kvp in info.bars)
         {
            _opens[kvp.Key] = kvp.Value.Open;
         }
      }

      public override void SimBar(NewBarInfo info)
      {
         SetHighLows(info);
         SetOpens(info);
         base.SimBar(info);
      }

      public override void SimOpen(NewBarInfo info)
      {
         SetOpens(info);
         _highs.Clear();
         _lows.Clear();
         base.SimOpen(info);
      }

      public override void SimHighLow(NewBarInfo info)
      {
         _opens.Clear();
         SetHighLows(info);
         base.SimHighLow(info);
      }

      public override void SimTick(Symbol symbol, TickData tick)
      {
         _opens.Remove(symbol);
         _highs.Remove(symbol);
         _lows.Remove(symbol);
         base.SimTick(symbol, tick);


Posted Sunday February 07 2010
I created class doubles _open, _high, and _low and tried to populate these with on new ticks based on the tick type. However, all of the tick types are marked "Trade"

When I step into the below code, I get four ticks for each bar (OHLC), but they have tickType = Trade. Any ideas why this is happening or how to identify which ticks are OHLC, perhaps just order? But shouldn't the Tick.ticktype be populated correctly?


public override void SimTick(Symbol symbol, TickData tick)
      {
switch (tick.tickType)
{
case TickType.OpenPrice:
this._open = tick.price;
break;

case TickType.HighPrice:
this._high = tick.price;
break;

case TickType.LowPrice:
this._low = tick.price;
break;
}
Posted Sunday February 07 2010
Try turning putting the following line of code in your system's Startup method:
SystemData.CreateTicksFromBars = false;

Then SimBar should be called, and you should be able to inspect those bars to get the OHLC values for your calculations.

The SimOpen and SimHighLow methods aren't used anymore, and will be removed in the next RightEdge build.

Thanks,
Daniel
Pinch Posted Sunday February 07 2010
I added the following code to my system startup in right edge
SystemData.CreateTicksFromBars = false;


However, the plugin code in VStudio doesn't compile. I had to comment out SimBar and the other two unused functions in order for the project to compile.

Error is that there is: no suitable method to override for SimBar()
Posted Sunday February 07 2010
Was the plugin compiling before?

It sounds like the plugin may be referencing the wrong version of Common.dll. Remove the reference and then re-add a reference to Common.dll from the RightEdge installation folder.

Thanks,
Daniel
Posted Sunday February 07 2010
In order to compile the plugin before, I had to comment out SimBar(). So, now that I un-comment SimBar() I have the same problem.

Other users have reported this before:
http://www.rightedgesystems.com/forums/Topic6660-13-3.aspx?Highlight=slippage

I tried re-referencing common.dll but same problem.
Posted Sunday February 07 2010
What version of RightEdge are you using? Can you post the code to your paper broker that won't compile?

Thanks,
Daniel
Posted Sunday February 07 2010
System is Windows 7 x64
Visual Studio 2008
Right Edge 2008 Ed 2 Build 14

Ok -- I noticed that there are two versions of common.dll: one in the ~\plugins directory and another in \. I tried referencing one and then the other, but I still get the same compiler error.

No suitable method found to override: SimBar(RightEdge.Common.NewBarInfo) no suitable method found to override

Here is the simple code i'm running:

using System;
using System.Collections.Generic;
using RightEdge.Common;

namespace RightEdge.Plugins
{
   public class SlippagePaperTrader : PaperBroker.PaperTrader
{
#region header
public override string ServiceName()
      {
         return "Paper Trade Broker With Slippage";
      }

      public override string Author()
      {
         return "James Luong";
      }

      public override string Description()
      {
         return "This is a paperbroker that calculates slippage based on 1/2 of O-H, O-L depending on trade";
      }

      public override string CompanyName()
      {
         return "Yye Software";
      }

      public override string Version()
      {
         return "1.0";
      }

      public override string id()
      {
         return "{A845D94F-B0E0-4368-8507-62B7DB282F7A}";
}

#endregion
Dictionary _highs = new Dictionary();
      Dictionary _lows = new Dictionary();
      Dictionary _opens = new Dictionary();

private void SetHighLows(NewBarInfo info)
{
_highs.Clear();
_lows.Clear();
foreach (var kvp in info.bars)
{
_highs[kvp.Key] = kvp.Value.High;
_lows[kvp.Key] = kvp.Value.Low;
}
}

private void SetOpens(NewBarInfo info)
{
_opens.Clear();
foreach (var kvp in info.bars)
{
_opens[kvp.Key] = kvp.Value.Open;
}
}

public override void SimBar(NewBarInfo info)
{
SetHighLows(info);
SetOpens(info);
base.SimBar(info);
}

public override void SimTick(Symbol symbol, TickData tick)
{
_opens.Remove(symbol);
_highs.Remove(symbol);
_lows.Remove(symbol);
base.SimTick(symbol, tick);
}

      protected override bool ShouldFill(BrokerOrder order, double curPrice, bool bGap, bool bClose, out double fillPrice)
      {
         if (!base.ShouldFill(order, curPrice, bGap, bClose, out fillPrice))
         {
            //   Shouldn't fill order at all
            return false;
         }

         double slippage = 0;

double open, low, high;

_opens.TryGetValue(order.OrderSymbol, out open);
_lows.TryGetValue(order.OrderSymbol, out low);
_highs.TryGetValue(order.OrderSymbol, out high);

         //   Determine if slippage should increase or decrease the fill price
if (order.TransactionType == TransactionType.Sell || order.TransactionType == TransactionType.Short)
{slippage = (low - open) / 2;}
else
{slippage = (high - open) / 2;}

         //   Adjust the fill price based on the slippage
         fillPrice = open + slippage;
         
         if (fillPrice < 0)
         {
            return false;
         }

         return true;
      }
   }
}
Posted Sunday February 07 2010
The signature of the SimBar method has changed. The argument it takes is now of type NewBarEventArgs. So the method declaration should look like this:

public override void SimBar(NewBarEventArgs args)

If you are using Visual Studio, you should be able to type "override" in the class and intellisense will show you the methods you can override and you can select one to have it automatically create that method with the correct signature.

Thanks,
Daniel

Posted Sunday February 07 2010
Ahhhh... Thank you! Smile


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems