Jump to content
Medved Trader Forums

Mike Medved

Administrators
  • Posts

    1,542
  • Joined

  • Last visited

  • Days Won

    124

Everything posted by Mike Medved

  1. Basically, any snippet of the C# code that would work in advanced paintbar could be isolated into a separate file and included via the #include. The #include is there so that you can have a library of functions you use and #include it in paintbars without repeatedly inserting the same code in every paintbar where it would be used.
  2. I fixed this - the fix will be in next release. Basically the backfillAndGetCandles's "full" method was not being passed on.
  3. well.. you have Qty as 30/(Ask-PriceAtMouse). Should really be floor(30/(Ask-PriceAtMouse)) - because quantity is an integer. So then the total amount of the transaction would be (since it is a Market Buy, let's assume it is at Ask) Ask * floor(30/(Ask-PriceAtMouse)) You don't want that to be more than $10k, so that amount would be Min(10000, Ask * floor(30/(Ask-PriceAtMouse))) Thus the appropriate quantity should be that amount divided by Ask (and floor taken for it so that it is integer) floor(Min(10000, Ask * floor(30/(Ask-PriceAtMouse))) / Ask)
  4. Yes. The problem (a bit) is that hotkey is executed once while paintbar is executed potentially 100,000 times within a fraction of a second. Accessing the account data is not fast... Will check on it.
  5. Paintbars/scans are not tied to any particular account... It's true you could specify the account right in the function call. Would have to think on it.
  6. When I send out the backfillAndGetCandles, I first receive these messages { "cmd": "backfill", "reqID": "1246", "success": "OK", "resultcode": 200, "result": { "action": "started", "type": "OHLC", "sym": "NVDA" } } ... and then { "cmd": "backfill", "reqID": "1246", "success": "OK", "resultcode": 200, "result": { "action": "finished", "type": "OHLC", "sym": "NVDA" } } ... and only after that, the { "cmd": "getCandles", "reqID": "1246", "success": "OK", ... etc. Is this not what happens for you?
  7. When you say maximum position size, you mean you don't want to add more to existing position if it is $10K?
  8. Hm ok it will have to be treated differently from every other indicator. I will look into that.
  9. If you open a historical chart for stock A, set VWAP to anchor at 1/1/2020 then close it. Then open a historical chart for stock B, set VWAP to anchor at 1/1/2021 then close it. Then re-open historical chart for stock A, the VWAP anchor will be remembered. But, if you switch charts by either typing a new symbol in the chart or by using linked symbols, the anchor date (or any other parameters for any other indicators) won't change.
  10. Ok - that OTA order that you have in the hotkey - is it executed? Because that red error box would indicate that it wasnt. I will try running the same thing here will look.
  11. Conditional orders, in secondary legs, cannot have absolute price values right now. They have to be relative to the main price. Let me investigate if that can be changed.
  12. Sure. Change if (TradingDay.IsPreMarket) to if (Timestamp < TradingDay.SessionStart.AddMinutes(-30))
  13. Ok I see why this is happening. The historical scanner assumes that you don't need more than 500 candles to work on. Apparently a bad assumption. I removed that. Well, made it bigger - 3000 candles. 3000 trading days back - hopefully that's more than anyone would need.
  14. .fctbNone{ color:#000000; } .fctbStyle4{ color:#0000ff; } .fctbStyle2{ color:#008000; } .fctbStyle3{ color:#000000; } .fctbStyle2Style3{ color:#000000; } .fctbStyle6{ color:#808080; }Note that everything *after* MainCalculation is just standard code inserted by MT when you make it a state machine. Also - to make it work right, it has to be run as an Intraday scan, with the extended hours set to Always. ==================================================================================================================== private struct PaintbarState { public Double PreMarketVolume; } int LastDayNumber = -1; FIFOQueue PreMarketVolumes = new FIFOQueue(5); // averaging on 5 days period Boolean WasPreMarket = false; public void MainCalculation() { SetDaysNeeded(5); // need 5 day's data for this to work if (TradingDay.DayNumber != LastDayNumber) // initialize to 0 start of every day { CurrentState.PreMarketVolume = 0; LastDayNumber = TradingDay.DayNumber; } if (TradingDay.IsPreMarket) { CurrentState.PreMarketVolume += BarVolume; WasPreMarket = true; } else { if (WasPreMarket) // add the premarket volume AFTER the premarket ends to the average queue { WasPreMarket = false; PreMarketVolumes.Add(CurrentState.PreMarketVolume); } } .fctbNone{ color:#000000; } .fctbStyle3{ color:#000000; } .fctbStyle1{ color:#800000; } SetScanResultColumnName(0, "Avg Premarket"); SetScanResult(0, Convert.ToInt64(PreMarketVolumes.Average)); } /// <summary> /// INITIALIZES paintbar. Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar /// NOTE: do NOT initialize the CurrentState here - the PaintbarClearState will be called AFTER this call, and will wipe it out. /// </summary> private void PaintbarInitialize() { } /// <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 /// and initialize whatever variables you place into it. This is called AFTER PaintbarInitialize /// </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; }
  15. Well yes That is what FIFO queues are about - to calculate averages for last N periods. Send me your scan and I will add that.
  16. 1. This is EXTREMELY inefficient. It has to loop through the last 1000 candles EVERY time there is a trade in the stock. I am surprised your MT didn't slow down to a crawl. 2. This says: if any of the last 1000 candles had a volume that was greater than 300M and went up more than 50% from low to high in ONE candle... Was there a candle in SPI that fit that criteria?
  17. Sorry. Of course I mean TradingDay.SessionEnd Timestamp >= TradingDay.SessionEnd.AddMinutes(1)
  18. Yes, scan results only show if the condition is true on the current - last - candle of the chart. Unlike the paintbar that can show if the condition was true on any candle in the chart. That's the whole point of the scanner - you can scan 3000 symbols and show only the tickers for which the condition is NOW true. You can, of course, write the scanner with a condition "if this condition was true in any of the last N candles", too.
  19. Thing is, 4pm candle (anything that is traded at or after 4pm) is considered afterhours. IsAfterHours in TradingDay is defined as Timestamp >= SessionEnd && Timestamp <= DayEnd So instead of IsAfterHours in your code, if you want to give a 1 min buffer you can just say Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)
  20. Note that the alerts ONLY appear if they happen on the LAST (current) candle's calculation.
×
×
  • Create New...