Jump to content
Medved Trader Forums

Jason

Members
  • Posts

    208
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Jason

  1. I use IB's TWS and use the VWAP indicator they provide with upper and lower VWAP lines but I cannot get the VWAP indicator in MT to produce the same lines. I am using the default settings for the indicator in IB. As far as I can gather the upper and lower VWAP lines in TWS correspond to the VWAP bands indicator in MT but for all my efforts I can't get them to look the same. In TWS the period is 1 day whereas the indicator in MT asks for the "trade sizes". To get them to match as closely as I can (on a 5 minute chart) I used a high number for the standard of deviations in MT. Is there any way this indicator can be fixed or modified for use in MT? Here is a link to how TWS is implementing VWAP: https://www.interactivebrokers.com/en/software/tws/usersguidebook/technicalanalytics/intradayvwap.htm

    Also, I will include below screen captures of how they differ in both platforms. It's important to me that they display the same way as these upper and lower VWAP lines often stand as lines of support and resistance and can define price channels. It can affect my trade decisions if these lines appear to be trending up in one platform and down in another or do not display correctly in the first candlesticks of the trading day. The settings I used in MT were St. Deviation Period of 100 with 0 min and max trade size.

    Also, I have noticed the option for the center line between the bands in the MT indicator, the VWAP line option, doesn't appear to do anything. The VWAP line is never drawn. In order to show the VWAP proper I have to add the plain VWAP indicator separately.

    Thanks!

     

    IB-VWAP.jpg

    MT-VWAP.jpg

  2. I know this topic is a little old but I was encountering the same obstacle recently and found a solution.

    1. Run your scan in TWS.

    2. Right click on a row in the scan results window. A menu will pop-up.

    3. At the bottom of the menu, select "Export Page Content." A window will be presented where you can save the scan results to a .csv file. Save the results as a .csv file and open the file in Excel. All of the results from the scan, including the stock symbols, will be properly separated into their own cells in the spreadsheet. Select the symbols you want to import and use CTRL-C to copy them and SHIFT-INSERT to paste them into Medved Trader.

  3. This would be quite valuable. With every executed order that prints if we could pull the bid and ask and store it to say, measure how much the spread fluctuates over a given time frame... You could create an indicator to measure spread volatility. Might provide some really good insight into how dangerous a particular stock would be to trade.

  4. If I remove the condition for the crossup over the EMA the paintbar highlights just the first candlestick of the day. But because the high of that candlestick is equal to the high of the day for every candlestick in the chart the paintbar should be highlighting every candlestick. The comparison should return true for each candlestick. The chart that I'm using is for AMAT for Friday's activity. Here is the relevant code:

    public void MainCalculation()
    {
        var SessionInformation = GetTradingSessionInfo(Timestamp);

        if (SessionInformation.DayNumber != CurrentState.LastDayNumber)
        {
            CurrentState.LastDayNumber = SessionInformation.DayNumber;
            CurrentState.DayHigh       = High;
        }

        CurrentState.DayHigh = Math.Max(CurrentState.DayHigh, High);
        
        if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5))
            {
                CurrentState.FirstCandleHigh = High;
            }
        
            if ((CurrentState.FirstCandleHigh == CurrentState.DayHigh))
            {

                        SetColor(SysColor.Positive);

            }
    }

  5. 47 minutes ago, Mike Medved said:

    > A few things. First, I am not sure if you mean to compare the highs for exact match. That is unlikely to happen. Maybe you mean the high is higher than the first candle high?

    Yes, an exact match. Because the point is to make sure that the cross up over the EMA is only detected in a chart where the price action up to that point in the day has moved down from the first candlestick in the session. In other words, the high of the first 5 minute candle is the highest price reached in the session up to the point of the EMA cross over.


    >Second, I don't know if you really want to check for the "crosses up" condition. It is very unlikely that the candle that matches the first candle high will cross the EMA as well. You probably mean if Close is above the EMA?

    The idea, was to store the high of the first 5 minute candlestick so that it could be retrieved and used later at some point. Then, to store the highest price reached for the day thus far. These two values wouldn't change so long as the price action never moved above the high of the first 5 minute candle. Those two values would be retrieved and compared later at the time of the EMA test. The code I use for the EMA crossover, when I test it independently works perfectly. I was hoping that the code wouldn't be requiring the EMA crossover to occur on the first 5 minute candlestick. If the high of the day and first candle high are variables that have been stored properly it shouldn't do that.

    >And third - your code will only register the first five minutes' high if you use five-minute candles. If you use one-minute candles, you'd have to change the code. Do you only use this on five-min candles?

    I was planning on designing it for the 5 minute chart as that is the most important to me and the parameterizing the code later to expand it's capabilities.

     

  6. Okay, thanks because that worked pretty nicely. It does trigger on the chart whenever a new high is reached but I have developed it into the code I have below and am encountering a new issue. I have tested and confirmed that the code below using just the comparison is able to highlight the first candlestick of the day when the high of that candlestick is equal to the high of the day. Now need to use further conditions to narrow down which candlesticks get highlighted given that the two are equivalent. Given that the high of the first candlestick is equal to the high of the day, I need the paintbar to highlight the candlestick that crosses up over an indicator like an EMA. When I eliminate the first requirement I can get it to highlight cross-overs and other conditions but as soon as I implement the requirement for the highs to be the same the paintbar doesn't display anything on the chart. I have tried compounding both conditions with "&&" in one line and separating them out into nested IF statements to no avail. Here is the code:

    public void MainCalculation()
    {
        var SessionInformation = GetTradingSessionInfo(Timestamp);

        if (SessionInformation.DayNumber != CurrentState.LastDayNumber)
        {
            CurrentState.LastDayNumber = SessionInformation.DayNumber;
            CurrentState.DayHigh       = High;
        }

        CurrentState.DayHigh = Math.Max(CurrentState.DayHigh, High);
        
        if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5))
            {
                CurrentState.FirstCandleHigh = High;
            }
        
            if ((CurrentState.FirstCandleHigh == CurrentState.DayHigh))
            {
                if (Close.CrossesUp(EMA_10, 0))
                {
                        SetColor(SysColor.Positive);
                }
            }
    }

    /// <summary>
    /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
    /// </summary>
    private void PaintbarInitialize()
    {
        CurrentState.FirstCandleHigh = 0.00;
    }

    /// <summary>
    /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc
    /// </summary>
    private struct PaintbarState
    {
        public double FirstCandleHigh;
        public int LastDayNumber;
        public double DayHigh;
    }

    /// <summary>
    /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
    /// </summary>
    private PaintbarState CurrentState;

    /// <summary>
    /// Holds saved PB state - internal
    /// </summary>
    private PaintbarState SavedState;

    /// <summary>
    /// Is called at start of paintbar calculation, should be used to clear the paintbar state
    /// </summary>
    private void PaintbarClearState()
    {
        CurrentState               = new PaintbarState();
        CurrentState.LastDayNumber = -1;
    }

    /// <summary>
    /// Saves paintbar state (called internally).
    /// </summary>
    private void PaintbarSaveState()
    {
        SavedState = CurrentState;
    }

    /// <summary>
    /// Restores paintbar state (called internally).
    /// </summary>
    private void PaintbarRestoreState()
    {
        CurrentState = SavedState;
    }

     

  7. Okay, I think I've figured out what's happening. When I use SymbolData.High it's pulling the high of the day as stored from all market activity that occurred from both before the opening bell and after the closing bell. Technically this makes sense, however, my intent is to test if the high of the day throughout the period from 9:30 AM to 4:00 PM is the same as the high of the first 5 minute candlestick. Is there an alternative to SymbolData.High which would present a better comparison to achieve this?

  8. Well, I have tried making this change but am still getting very inconsistent results. On many symbols it works, but on others it doesn't. It works, for example, on ROKU, YELP, SQ, but not on XRAY, GOOGL or MCHP. I have tried using:

    if ( High == (float)SymbolData.High )

    which fixes the problem for GOOGL but not the others.

    Here is the code as it stands now:

    public void MainCalculation() { if ( Math.Abs(High-SymbolData.High)<0.00001 ) { SetColor(SysColor.Positive); } }

  9. Sorry, not sure why this is happening but I often submit a post that ends up empty somehow which forces me to rewrite everything.

    Okay, so because I need to use it for the paintbars I want to create I went back and tested SymbolData.High as I have encountered unexpected results in using it previously. Using the simple code below I am able to highlight the candle where the high of the day occurs for the symbol ONCE but cannot get it to work on any of the other symbols I've tested. I've tried it on TWLO, Z, HTZ, WTW, DF... I have tried it with and without state keeping, just in case, and cannot get it to work reliably. I don't know why it would matter but I've tested this on a 5 minute chart in after hourse trading. Also, the code has been the same across all tests and there are not any other indicators on the chart.

     

    
    
    
    

    public void MainCalculation()
    {
        if ( High == SymbolData.High )
        {
            SetColor(SysColor.Positive);
        }

    }

     

  10. Okay, that being the case then the first timestamp the paintbar receives should be the timestamp of the first 5 minute candle on the chart that I have applied that paintbar to. And what about SymbolData.High? If the last trading session took place on, say, Friday and I used a paintbar that included SymbolData.High and applied it to the chart on, say, Sunday would it return the high of the day on Friday or return nothing since I was applying it on Sunday?

  11. Okay, thank you very much for your patience.  For some reason I was thinking that I couldn't use an access modifier on a variable within a struct. Now I have another question for you. I'm currently trying to test this paintbar and flesh it out on chart data from a prior session a couple of days ago. From the help files I think I would need DayNumber for this but they state that DayNumber is " the # of the day in the list of trading sessions ." What list would this be though? Is it relative to the current day? Not sure how this is used. Or maybe there is an easier way? Timestamp is automatically going to refer to the current candlestick but is the session information being pulled internally from the current day or is it derived from the timestamp of the candlestick data that I'm feeding it on my 5 minute chart? If it's the latter then I must be making an error somewhere else since it should be showing up on my chart.

     

    Thanks again!

  12. Okay, I've changed the code as shown below, however, now I'm getting the following two errors:

    37, 24    CS1002    ; expected    
    37, 40    CS1519    Invalid token ';' in class, struct, or interface member declaration    

    The parser seems to take issue with the following line in the PaintbarState struct:

        double CurrentState.FirstCandleHigh;

    at the period and semicolon. Also, if I were to retrieve FirstCandleHigh from the first state would I need to manually call PaintbarSaveState() in the first part of the IF statement and read it back under the ELSE statement with something like SavedState.FirstCandleHigh?  Here is the full code:

     

    public void MainCalculation()
    {
        var SessionInformation = GetTradingSessionInfo(Timestamp);
        
        if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5))
            {
                var CurrentState.FirstCandleHigh = High;
                return;
            }
            
        else
                
        if ((CurrentState.FirstCandleHigh == SymbolData.High) && (SymbolData.GapPercent <= -3) && Close.CrossesUp(EMA_10, 0))
            
            {
                SetColor(SysColor.Positive);
                TriggerAlert("Reversal", @"Reversing");
                SetScanResult("Reversal");
                return;
            }

    }

    /// <summary>
    /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
    /// </summary>
    private void PaintbarInitialize()
    {
        var CurrentState.FirstCandleHigh = 0.00;
    }

    /// <summary>
    /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc
    /// </summary>
    private struct PaintbarState
    {
        double CurrentState.FirstCandleHigh;
    }

    /// <summary>
    /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
    /// </summary>
    private PaintbarState CurrentState;

    /// <summary>
    /// Holds saved PB state - internal
    /// </summary>
    private PaintbarState SavedState;

    /// <summary>
    /// Is called at start of paintbar calculation, should be used to clear the paintbar state
    /// </summary>
    private void PaintbarClearState()
    {
        CurrentState = new PaintbarState();
    }

    /// <summary>
    /// Saves paintbar state (called internally).
    /// </summary>
    private void PaintbarSaveState()
    {
        SavedState = CurrentState;
    }

    /// <summary>
    /// Restores paintbar state (called internally).
    /// </summary>
    private void PaintbarRestoreState()
    {
        CurrentState = SavedState;
    }

     

  13. My goal is to store the high of the first 5 minute candlestick in a variable and then retrieve it for comparison but I'm stuck on this error message:

    37, 5 CS0825 The contextual keyword 'var' may only appear within a local variable declaration

    So far, this is the code I've worked up but through searching the forums I haven't been able to get any further than this.

    Any help would be appreciated.


    public void MainCalculation()
    {
    var SessionInformation = GetTradingSessionInfo(Timestamp);

    if (Timestamp <= SessionInformation.SessionStart.AddMinutes(5))
    {
    var FirstCandleHigh = High;
    return;
    }

    else

    if ((FirstCandleHigh == SymbolData.High) && (SymbolData.GapPercent <= -3) && Close.CrossesUp(EMA_10, 0))

    {
    SetColor(SysColor.Positive);
    TriggerAlert("Reversal", @"Reversing");
    SetScanResult("Reversal");
    return;
    }

    }

    ///
    /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
    ///
    private void PaintbarInitialize()
    {
    CurrentState.FirstCandleHigh = 0.00;
    }

    ///
    /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc
    ///
    private struct PaintbarState
    {
    var FirstCandleHigh;
    }

    ///
    /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
    ///
    private PaintbarState CurrentState;

    ///
    /// Holds saved PB state - internal
    ///
    private PaintbarState SavedState;

    ///
    /// Is called at start of paintbar calculation, should be used to clear the paintbar state
    ///
    private void PaintbarClearState()
    {
    CurrentState = new PaintbarState();
    }

    ///
    /// Saves paintbar state (called internally).
    ///
    private void PaintbarSaveState()
    {
    SavedState = CurrentState;
    }

    ///
    /// Restores paintbar state (called internally).
    ///
    private void PaintbarRestoreState()
    {
    CurrentState = SavedState;
    }

  14. Okay, just to begin with a simple test case I tried:

    
     

    public void MainCalculation() { if (High == SymbolData.High) { SetColor("High", SysColor.MainIndicator3); return; } }

    on a 5 minute chart but it doesn't highlight the candlestick with the high. I suspect there's something about the how it's calculated that I don't understand. According to this I'm expecting that the paintbar will iterate through each candlestick in the chart in sequence comparing the high of that candlestick to the high of the day.

  15. I am trying to write paintbar code for a scan which would alert given conditions such as the high of the day is equal to the high of the first 5 minute candlestick in the chart or that the low of the day was reached by the previous candlestick, etc.. How would I accomplish this? I am assuming I would need state keeping to do this since the high/low of the day would need to be retained for each new paintbar calculation but I have tried using CurrentState and SymbolData as a test without any success. Is there a better way?

    Thanks!

  16. My apologies. I missed the email as I hadn't caught it on Friday and then my internet service failed over the weekend. I think I had the checkboxes shown confused with the one in the Paintbar rule editor where we can select it as an alert. And it just hadn't occurred to me that once the Paintbar was added as an indicator to the chart that I would have to select it for each rule in that window.

    Thanks for checking it out and sorry for the wasted time.

×
×
  • Create New...