Betting Bot Automation - Macro repeat

Discussion regarding the spreadsheet functionality of Bet Angel.
Post Reply
sjoc20
Posts: 14
Joined: Mon Nov 30, 2009 12:24 pm

Hi all,

I'm at the final stages of creating my first automatic trading bot using VBA and I am in need of some help to make it truly automatic.

At the moment the bot will find the favorite and bet accordingly according to some pre-defined global settings a user sets such as how much liquidity is needed to enter the market, what to stake according to your balance, whether to green, etc etc etc etc and etc!

..But to make it truly automatic I'm stuck with making it repeat this one time process (as i'm using F5 to test once after workbook opens). For example the main macro runs when the workbook opens, i.e. the private sub workbook_open() function is started with my main function being told to run which does all the figuring out mentioned above (for those only used to excel formulas and not VBA - this process on a conceptual level is not really any different - only how its 'coded' if you like). This then makes the first bet, i.e. the 'BACK OFFSET:1 WITH_GREENING:TRUE...' is put into the bet angel sheet under the favorite runner. What i need help on now (even if you guys can only help conceptually - would still be great) is how do get it to repeat this whole process and continue repeating or automatically do my physical typing of F5 periodically.

I.E. 1. NO LOOP suggestions please (like a for loop to run macro x amount of times)
2. NOT a call to main at the end of the main function to repeat itself when it happens to complete (unless this is how it must be done)
3. i.e. i want it to be like its reading what has happened so far then repeat itself when all bets are matched. It will carry on doing this until it realises the race has finished.

I.E the main question I am asking is how do i get a macro to continually repeat itself. it sounds simple but for some reason i'm running into errors, performance issues and finding little support online believe it or not.

Thanks for your help. If i need to make myself clearer as i know i can be confusing half the time then please say and i'll repost this question in a different way. thanks again.
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

"want it to be like its reading what has happened so far then repeat itself when all bets are matched"

Maybe you could use the "unmatched bets" cell (C5) as a flag?

I.E, if range("C5").value=0 then.........

If you put your routine in as a worksheet calculate event, it should run all the time.

Nigel.
sjoc20
Posts: 14
Joined: Mon Nov 30, 2009 12:24 pm

hi nigelk,

thanks for the help but i've just managed to figure out how to get it to repeat itself :D LOL... and its simply to use a Application.OnTime function which will repeat a specified routine at a specified interval rather than before where my efforts were draining resources or generating run-time errors!! It's a function i wasn't aware of and missed when searching the API so i guess its an achievement to finally solve. thanks anyway.

BTW, 'reading' was never a problem and it would do this and act accordingly at least once. just getting it to repeat that process by itself so i could go away was the pain. :x ..but thank you anyway.

I am intrigued by your suggested solution however even tho i solved the main issue at hand as yours could still turn out to be better. ;)

its always good to continually learn too so could you explain how you mean to put my routine as a 'worksheet calculate event'. I'm not sure what that is?

sjoc20

EDIT: for anyone else interested Application.OnAction can be used to repeat a function (get a macro to repeat itself) as well but according to an event rather than a specific time, i.e. i think this can be applied to repeating a macro when a bet has been matched rather than repeating a macro before a bet has had a chance to be matched.
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

Right click on the Bet Angel sheet tab and select "view code"

From the left hand drop down box, (currently showing "General"), select "worksheet".

Then on right hand drop down select "calculate", then
just put your code in. Note it will only run if you have a formula present in the worksheet.

Private Sub Worksheet_Calculate()

'My Code............
MsgBox "Formula Calculation"

End Sub
sjoc20
Posts: 14
Joined: Mon Nov 30, 2009 12:24 pm

hey Nigel,

ha! i should of realised what you meant before with 'Worksheet' calculate event. after all i've used the 'worksheet_open' function!! :oops: ...in my defense tho i'm crossing over from Java, various scripting languages and Objective-C but have never touched VB or any .net let alone VBA :!:

I see how your way would work tho and of course the reason it would need a formula on the worksheet is so that it can generate the event that instantiates the 'Worksheet_Calculate' sub routine. In this instance tho, i don't want a formula on the sheet nor do i think it would be the right/best way of getting a macro to continously run. i did try fixing my problem with the 'Worksheet_SelectionChange' in a similar way but again (i can't remember why) i had problems.

Anyway, thank you very much for your help Nigel. Problem solved.

Steve
Post Reply

Return to “Bet Angel - Spreadsheet / Excel chat”